Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My code is as follows

IUnityContainer container = new UnityContainer(); 

container
.ConfigureAutoRegistration()
.LoadAssemblyFrom(typeof(Test).Assembly.Location)
.LoadAssemblyFrom(typeof(ITest).Assembly.Location)
.ApplyAutoRegistration();

This is my first question.

I'm not sure whether I have used the LoadAssemblyFrom method correctly here:

ITest test = container.Resolve<ITest>(); 

When I try to compile I get the exception "ResolutionFailedException".

What am I doing wrong?

Thanks for your time in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
191 views
Welcome To Ask or Share your Answers For Others

1 Answer

It appears that what you are looking for is this:

container.ConfigureAutoRegistration()
         .LoadAssemblyFrom(typeof(ITest).Assembly.Location)
         .LoadAssemblyFrom(typeof(Test).Assembly.Location)
         .Include(If.ImplementsITypeName, Then.Register())
         .ApplyAutoRegistration();

This will tell Unity.AutoRegistration to register all types where there is an interface with the same name, prefixed with I.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...