Solved

TypeAccessException resolving with Unity

Posted on 2010-09-23
1
897 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
1 Comment
 
LVL 14

Accepted Solution

by:
existenz2 earned 500 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Using Simpleject with Class Library 11 25
LINQ question 7 21
Problem to open Excel file 15 39
Copy/Clone an object. 9 10
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now