weimha
asked on
TypeAccessException resolving with Unity
I have an Interface that I want to be internal and an implementation of that interface that I want to be internal.
I use Unity to resolve the type as shown below.
When I run my unit test I get an TypeAccessException when I try to resolved the interface. When I make the implementation public it works fine.
The Unity Containter, interface and class all exist in the same project. Why can't my container resolve the type when the class is internal?
I use Unity to resolve the type as shown below.
When I run my unit test I get an TypeAccessException when I try to resolved the interface. When I make the implementation public it works fine.
The Unity Containter, interface and class all exist in the same project. Why can't my container resolve the type when the class is internal?
public static class UnityManager
{
private static IUnityContainer _unityContainer = null;
public static IUnityContainer UnityContainer
{
get
{
if (_unityContainer == null)
{
_unityContainer = new UnityContainer();
_unityContainer.RegisterType<IQuoteDAL, QuoteDAL>(new ContainerControlledLifetimeManager());
_unityContainer.RegisterType<IQuoteManager, QuoteManager>(new ContainerControlledLifetimeManager());
_unityContainer.RegisterType<IApplicationDAL, ApplicationDAL>(new ContainerControlledLifetimeManager());
_unityContainer.RegisterType<IApplicationManager, ApplicationManager>(new ContainerControlledLifetimeManager());
_unityContainer.RegisterType<IPolicyAdminDAL, PolicyAdminDAL>(new ContainerControlledLifetimeManager());
_unityContainer.RegisterType<IPolicyAdminManager, PolicyAdminManager>(new ContainerControlledLifetimeManager());
_unityContainer.RegisterType<IAnnuityApplicationManager, AnnuityApplicationManager>(new ContainerControlledLifetimeManager());
_unityContainer.RegisterType<IProductionDAL, ProductionDAL>(new ContainerControlledLifetimeManager());
_unityContainer.RegisterType<IProductionManager, ProductionManager>(new ContainerControlledLifetimeManager());
_unityContainer.RegisterType<IAnnuityApplicationDAL, AnnuityApplicationDAL>(new ContainerControlledLifetimeManager());
_unityContainer.RegisterType<IAnnuityApplicationManager, AnnuityApplicationManager>(new ContainerControlledLifetimeManager());
_unityContainer.RegisterType<IEntityDAL, EntityDAL>();
_unityContainer.RegisterType<IEntityManager, EntityManager>();
_unityContainer.RegisterType<IHumanResourcesDAL, HumanResourcesDAL>();
_unityContainer.RegisterType<IHumanResourcesManager, HumanResourcesManager>();
}
return _unityContainer;
}
}
}
internal class HumanResourcesDAL: IHumanResourcesDAL
{
private IEntityDAL entityDAL;
internal IEntityDAL EntityDAL
{
get
{
if (this.entityDAL == null)
{
this.entityDAL = UnityManager.UnityContainer.Resolve<IEntityDAL>();
}
return this.entityDAL;
}
set { this.entityDAL = value; }
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.