2
ILog와 같은 특정 유형에 대한 속성 주입을 수행하는 모듈이 있습니다.자식 수명 범위에서 autofac 모듈을 상속합니다
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
{
registration.Activated += [doing property injection];
}
그것은 동일한 범위 내에서 잘 작동하지만 자식 범위에서, AttachToComponentRegistration가 트리거되지 않습니다 더 이상, 나는 재산 주입을 가능하게하기 위해 다시 모듈을 등록해야합니다.
내 질문은 어떻게 자식 수명 범위에 등록 된 모듈을 상속하는 것입니까? 아니면 이것을 할 수있는 다른 방법이 있습니까?
class Program
{
static void Main(string[] args)
{
var builder = new ContainerBuilder();
builder.RegisterModule(new TestModule());
builder.RegisterType<Test>().As<ITest>();
var container = builder.Build();
container.Resolve<ITest>().Say(); // output test11111
var scope = container.BeginLifetimeScope("nested", b =>
{
// b.RegisterModule(new TestModule());
b.RegisterType<Test2>().As<ITest2>();
});
scope.Resolve<ITest>().Say();
scope.Resolve<ITest2>().Say();
}
}
public interface ITest
{
void Say();
}
public class Test : ITest
{
public void Say()
{
Console.WriteLine("test1111111");
}
}
public interface ITest2
{
void Say();
}
public class Test2 : ITest2
{
public void Say()
{
Console.WriteLine("test2222222");
}
}
public class TestModule : Module
{
protected override void AttachToComponentRegistration(Autofac.Core.IComponentRegistry componentRegistry, Autofac.Core.IComponentRegistration registration)
{
Console.WriteLine("called for " + registration.Activator.LimitType);
base.AttachToComponentRegistration(componentRegistry, registration);
}
}
어떤 자동 팩스 버전을 사용하고 있습니까? –
관련이있을 수있는 문제가 있습니다. http://code.google.com/p/autofac/issues/detail?id=218 ... 또한 하위 범위에 구성 요소를 생성/등록하는 코드를 게시 할 수 있습니까? ? 감사! –
Nicholas, pls가 소스 코드 위에 체크 아웃했는데 "called for"가 중첩 된 범위 구성 요소에 표시되지 않습니다. –