English 中文(简体)
IoC - 物体动态成分
原标题:IoC - Dynamic Composition of object instances

是否有办法利用IoC、MEF(港口)或另一个DI解决办法,在物体制造时间而不是在组成时间对空气进行堆肥?

我目前的想法。 如果你有引起事件的物体,但你不会一度制造该物体并保存该物体,那么,在制造该物体时,你必须登记该活动操作员。 就我所知,大多数IoC集装箱都要求你登记组成中使用的所有类别,并打电话(Compose)使其掌握所有的依赖性。

我认为,这可能是可恶的设计(这里涉及遗产系统)之所以如此,是因为制造物体、依赖注射等的间接费用。

也许我有一些术语混在一起,但我的目标是避免起草一个框架,在物体的情形下“审视所有事件”,并利用例如法国空局的操作员(独立者)坚持一个非常具体的接口,[旅行管理]他们进入一个标的场,以便我的出口在申请启动时就得到呼吁。 因此,也许所有物体在申请开始时仍然可以构成,但我希望该系统能够发现和称呼所有物体,因为物体是制造和摧毁的。

最佳回答

通常,在DI/IoC环境中,你在现场处理的方式是使用抽象的工厂。 工厂是允许与集装箱直接互动的“ /em>级”,以便在出现新物体时解决附属问题。

public interface IWidgetFactory
{
    IWidget CreateWidget(...);
}

public class MyIocWidgetFactory : IWidgetFactory
{
    private IoCContainer container;

    public MyIocWidgetFactory(IoCContainer container)
    {
        if (container == null)
            throw new ArgumentNullException("container");
        this.container = container;
    }

    public IWidget CreateWidget(...)
    {
        // Assumes that the container is configured to create transient objects
        // for IWidget, not a singleton.
        return container.Resolve<IWidget>();
    }
}

请不要把这个问题与服务地点反家长混为一谈;不允许其他任何事情触及集装箱,只是工厂,而且只制造一种物体。

此时此刻,你刚刚通过<条码>IWidgetFactory,以达到在运行时间创造植被所需要的任何条件。 顺便说一遍——你现在就保持了DI。

问题回答

暂无回答




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签