I have 2 classes like this:
1)
public class EFInitializerLanguage : EFInitializerBase, IRepositoryInitializer<Language>
{
public IEntityRepository<Language> Create()
{
return this.Model.CreateObjectContext<LanguageData>(new SqlConnection(Utility.ConnectionStrings.ConnDefault));
}
}
2)
public class EFInitializerPerson : EFInitializerBase, IRepositoryInitializer<Person>
{
public IEntityRepository<Person> Create()
{
return this.Model.CreateObjectContext<PersonData>(new SqlConnection(Utility.ConnectionStrings.ConnDefault));
}
}
And the definition in Unity.config is (probably these are wrong and I couldn’t figure out what to do)
<unity>
<typeAliases>
<typeAlias alias="IRepositoryInitializer`1" type="Contracts.Repositories.IRepositoryInitializer`1, Contracts" />
<typeAlias alias="EFInitializerPerson" type="Data.Initializers.EFInitializerPerson, Data" />
<typeAlias alias="IRepositoryInitializerLanguage`1" type="Contracts.Repositories.IRepositoryInitializer`1, Contracts" />
<typeAlias alias="EFInitializerLanguage" type="Data.Initializers.EFInitializerLanguage, Data" />
<containers>
<container>
<types>
<type type="IRepositoryInitializer`1" mapTo="EFInitializerPerson" />
<type type="IRepositoryInitializerLanguage`1" mapTo="EFInitializerLanguage" />
</types>
</container>
</containers>
</unity>
You might think to use 1 EFInitializer instead of 2 or more, but because of the input and out type difference I couldnt not make it. At this point, I believe my current approach seems fine to me.
The error I get during RunTime is:
Resolution of the dependency failed, type =
“Contracts.DataManagers.ILanguageManager”, name = “”. Exception
message is: The current build operation (build key Build
Key[Contracts.DataManagers.ILanguageManager, null]) failed: The
current type, Contracts.DataManagers.ILanguageManager, is an
interface and cannot be constructed. Are you missing a type mapping?
(Strategy type BuildPlanStrategy, index 3)
It seems like, in the config file, the declarations must be different when it comes down to have 2 different classes that implements SAME interface.
I’d be very happy if you could point me out to the right direction.
Thanks in advance,
I cannot say this is an exact solution for my problem. But I thought of a workaround; Instead of using 2 EFInitializers, I merged in to one with generic types as in below:
and the unity configuration became into this:
Well, with this approach at least I would not have to write EFInitializer for each entity which is pretty cool for me.
As a result, this solution is not an exact match for my problem. Since, I still am working on the system design, perhaps I’ll run into same problem.
Thank you for your help.