English 中文(简体)
我如何在装满团结的集会上登记类型?
原标题:How do I register types in assemblies that haven t been loaded with Unity?

我想装上所有类型的接口,以便我可以把它称作一种方法。 然而,议会没有参考汇编时间。 他们将坐在双管上。

这是我能轻易与团结做的吗?

例如,我有这样的法典:

using (var container = new UnityContainer())
        {
            container.RegisterType<IModule>();

            var modules = container.ResolveAll(typeof(IModule));

            foreach (IModule module in modules) { module.Logon(); }

            Console.WriteLine("Done...");
            Console.ReadLine();
        }

当然,单元决不会因为议会刚刚变成双倍。 在我目前的大会中没有静态地提及这些问题。

或者,我是否必须做某种类型的议会。 LoadAssembly(A) 因此,我尽可能充满活力。 如果没有可能,我就不必在专案或法典中注明组别名称。

提前感谢。

最佳回答

团结本身并不装载任何集会。 它不使用类型物体,而是让《南极海生委》装载这些类型。

为了像你所希望的那样进行动态发现,你需要写一部小的法典,以便穿过双版的集会,把他们装上记忆,然后通过他们寻找你们感兴趣的类型。 如果你重新熟悉反转录器,那是很奇怪的。

在这里,你可以使用一些密码,通过双版名录,并确保每组装上:

    private static bool ForceLoadAssemblies()
    {
        foreach (var fileName in Directory.GetFiles(AppDomain.CurrentDomain.RelativeSearchPath, "*.dll"))
        {
            string assemblyName = Path.GetFileNameWithoutExtension(fileName);
            if (assemblyName != null)
            {
                Assembly.Load(assemblyName);
            }
        }
        return true;
    }

另一种选择是研究简化手续。 MEF是专门为动态发现案例设计的,而团结则更多地围绕内部依赖管理建立起来。

问题回答

暂无回答




相关问题
Unity (in PRISM) does (not) weird resolving...??!!

I m using PRISM and in the Bootstrapper class i did override the ConfigureContainer() method. There is nothing fancy in it just these lines: protected override void ConfigureContainer() { ...

Unity Configuration and Same Assembly

I m currently getting an error trying to resolve my IDataAccess class. The value of the property type cannot be parsed. The error is: Could not load file or assembly TestProject or one of its ...

Unity IOC, AOP & Interface Interception

I ve been playing around with Unity to do some AOP stuff, setting up via IOC like: ioc.RegisterType<ICustomerService, CustomerService>() .Configure<Interception>().SetInterceptorFor&...

How to Inject Open Connections with an IoC

First, my scenario. I have a service, BillingService, has a constructor like this: BillingService(IInstallmentService, IBillingRepository) The InstallmentService has a constructor that looks like ...

Unity view Registered Types during debug

Possibly a stupid question, but during debug I simply want to see the types that have been registered with my Unity container. I have tried going through the container in the watch window, but can t ...

Unity constructors

I have setup unity in my project and it is working for objects that don t have constructor injection implemented on them. The issue is now I do have an object which requires a custom object as a ...

StrucutureMap RhinoMock Record/Playback, Example needed

I m looking for some examples on how to do the following Mock Tests using StructureMap or Unity with NUnit. I have the following code structure public interface IDAL { List<Model> Method1(...

Unity Container Disposing and XML Web Service

I am registering some wrapers over un-managed objects in container. How can I dispose of them at the end of the container s lifetime? Please bear in mind I have an XML Web service.

热门标签