• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 911
  • Last Modified:

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?
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; }
        }
}

Open in new window

0
weimha
Asked:
weimha
1 Solution
 
existenz2Commented:
Your unit test is external, so the test will fail because classes are internal. You can't unit test those, because the interface is not publicly exposed.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now