0

LightInject IoC 容器中是否有“ObjectFactory.GetInstance”的类似物?

例如,我需要在继承自 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>();
    }
}
4

1 回答 1

0

我是 LightInject 的作者,恐怕您提供的有关您正在尝试做的事情的信息太少。如果这与 WCF 有关,请在 LightInject.Wcf 存储库 ( https://github.com/seesharper/LightInject.Wcf ) 中创建一个问题,并提供一个简单的“工作”示例来说明您正在尝试做什么

于 2016-11-09T13:39:22.963 回答