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