c# - How to register a named type mapping to resolve to the unnamed type mapping -


I am using the unit framework with the unit of work design pattern, my class structure is as follows:

  Public Interface IUnitOfWork {void save (); } Public Class MyContext: Object Contact, IUnitOfWork {Public Zero Save () {SaveChanges (); }}   

As I type myContext type mapping register:

  IUnityContainer unityContainer = new UnityContainer () .RegisterType & LT; MyContext & gt; (New ContainerControlledLifetimeManager ());   

I know I have done the following:

  Integration contactor. Registration Type & lt; IUnitOfWork, MyContext & gt; (); IUnitOfWork unitOfWork1 = Unity Container. Resolve & lt; IUnitOfWork & gt; (); IUnitOfWork unitOfWork2 = Unity Container. Resolve & lt; IUnitOfWork & gt; ();   

Then there can be an example as unitOfWork1 MyContext unitOfWork2 , as IUnitOfWork MyContext , which is a container controlled example map

However, what I have to do, instead of this:.

  unityContainer.RegisterType & lt; IUnitOfWork, Mikantax & gt; ("Myunate work"); IUnitOfWork unitOfWork1 = Unity Container. Resolve & lt; IUnitOfWork & gt; ("MyUnitOfWork"); IUnitOfWork unitOfWork2 = Unity Container. Resolve & lt; IUnitOfWork & gt; ("MyUnitOfWork");   

then solve two different instances of unitOfWork1 and unitOfWork2 to MyContext It matters to me, because they map to both MyContacts, which is still a container controlled example. It appears that when mapping is given, they do not solve other types of parameters in the same way.

Because of this, I need to type the name mapping because I have more than one different ObjectContext for all IUnitOfWork is applicable, so it Defining a global IUnitOfWork type mapping.

My question is just how can I use named type mapping but still retain the functionality of the first implementation.

NB I really have a PerResolveLifetimeManager in my real implementation, however ContainerControlledLifetimeManager highlights the point in the lower code.

edit

I fixed my problem by changing the registration of the class with the dependency property of iUnitOfWork Have done

Previously it was on the lines of:; Services & gt; (New InjectionConstructor (New ResolvedParameter & LT; IUnitOfWork & gt; ("MyUnitOfWork")))

  unityContainer.RegisterType & lt;   

However, instead of resolving a designated IUnitOfWork , I took a different approach and resolved the direct implementation instead:

  unityContainer .RegisterType & lt; Services & gt; (New Injection Constructor (New Hull Matterter 
);)

thanks,>

just pass the lifetime manager :

  Integration Container Registration Type & lt; IUnitOfWork, MyContext & gt; ("MyUnitOfWork", New Container Control Lifetime Manager ());   

Reason: You have registered a anonymous name example of container-controlled example of MyContext , not name One

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

c# - Confused over DLL entry points (entry point not found exception) -