LightInject IoC容器中的ObjectFactory.GetInstance模拟

时间:2016-11-09 13:06:52

标签: c# inversion-of-control light-inject

是否有" ObjectFactory.GetInstance"在LightInject IoC容器中?

例如,我需要解析继承自IServiceBehavior的自定义行为属性中的接口,但默认情况下我需要的接口未解析。

public class MyInspectorAttribute : Attribute, IOperationBehavior, IParameterInspector, IServiceBehavior
{
    public IExternalService ExternalServiceInstance { get; set; } //always null

    public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters) { }

    public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation) { }

    public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
    {
       dispatchOperation.ParameterInspectors.Add(this); 
    }

    public void Validate(OperationDescription operationDescription) { }

    public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
    {
        Console.WriteLine("Operation {0} returned: result = {1}", operationName, returnValue);
    }
}

public class CompositionRoot : ICompositionRoot
{
    public void Compose(IServiceRegistry serviceRegistry)
    {
        serviceRegistry.Register<IService1, Service1>();
        serviceRegistry.Register<IExternalService,ExternalService>();
    }
}

1 个答案:

答案 0 :(得分:0)

我是LightInject的作者,我担心你提供的信息太少,无法解释你想要做什么。如果这与WCF相关,请在LightInject.Wcf repo(https://github.com/seesharper/LightInject.Wcf)中创建一个问题,并提供一个简单的“工作”示例,说明您要执行的操作