how to use with unity?

Jun 26, 2012 at 2:12 PM

my config file like this:

<alias alias="IGenericRepository" type="ettaingroup.data.ef.Interfaces.IGenericRepository`1,ettaingroup.data.ef"/>
    <alias alias="Repository" type="ettaingroup.data.ef.Repositories.Repository`1,ettaingroup.data.ef"/>

 <alias alias="IPianoAreaService" type="PianoBusiness.BaseInfo.IPianoAreaService,PianoBusiness"/>
    <alias alias="PianoAreaService" type="PianoBusiness.BaseInfo.Impl.PianoAreaService,PianoBusiness"/>

<register type ="IGenericRepository" mapTo="Repository" name="pianoAreaDal"/>

<register type="IPianoAreaService" mapTo="PianoAreaService" name="pianoAreaService">
        <constructor>
          <param name="pianoAreaDal">
            <dependency name="pianoAreaDal"></dependency>
          </param>
        </constructor>
      </register>

and my service contructor like this:

private Repository<PianoArea> _pianoAreaDal;

        public PianoAreaService(Repository<PianoArea> pianoAreaDal)
        {
            _pianoAreaDal = pianoAreaDal;
        }

when i run test throw expection :

Resolution of the dependency failed, type = "PianoBusiness.BaseInfo.IPianoAreaService", name = "pianoAreaService".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type DbConnection cannot be constructed. You must configure the container to supply this value.
-----------------------------------------------
At the time of the exception, the container was:

  Resolving PianoBusiness.BaseInfo.Impl.PianoAreaService,pianoAreaService (mapped from PianoBusiness.BaseInfo.IPianoAreaService, pianoAreaService)
  Resolving parameter "pianoAreaDal" of constructor PianoBusiness.BaseInfo.Impl.PianoAreaService(ettaingroup.data.ef.Repositories.Repository`1[[PianoData.PianoArea, PianoData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] pianoAreaDal)
    Resolving ettaingroup.data.ef.Repositories.Repository`1[PianoData.PianoArea],pianoAreaDal
    Resolving parameter "context" of constructor ettaingroup.data.ef.Repositories.Repository`1[[PianoData.PianoArea, PianoData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](System.Data.Entity.DbContext context, System.Boolean validateEntitesOnSave)
      Resolving System.Data.Entity.DbContext,(none)
      Resolving parameter "existingConnection" of constructor System.Data.Entity.DbContext(System.Data.Common.DbConnection existingConnection, System.Data.Entity.Infrastructure.DbCompiledModel model, System.Boolean contextOwnsConnection)
        Resolving System.Data.Common.DbConnection,(none)

how to do ?

Coordinator
Jun 26, 2012 at 3:22 PM

WIll have to get back to you on Unity integration.

Jun 27, 2012 at 1:32 AM

I have resolved it ,thanks!