?
Solved

TypeAccessException resolving with Unity

Posted on 2010-09-23
1
Medium Priority
?
908 Views
Last Modified: 2013-11-11
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
Comment
Question by:weimha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
existenz2 earned 2000 total points
ID: 33752242
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question