Unity.AutoRegistration?公约基础的登记统一 [英] Unity.AutoRegistration ?? Convention Based Registration Unity

查看:152
本文介绍了Unity.AutoRegistration?公约基础的登记统一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的code如下:

IUnityContainer container = new UnityContainer(); 

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

这是我的第一个问题。

This is my first question.

我不知道我是否已经使用了LoadAssemblyFrom方法正确位置:

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

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

当我尝试编译我得到的异常ResolutionFailedException。

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

我是什么做错了吗?

感谢您的时间提前。

推荐答案

看来,你正在寻找的是这样的:

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();

这将告诉Unity.AutoRegistration注册各类哪里有同名的,pfixed与我$ P $的接口。

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

这篇关于Unity.AutoRegistration?公约基础的登记统一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆