2014-01-10 55 views
0

我有兩個物體像這樣訪問依賴的對象類型:Autofac:在解決時間

public class A : IA 
{ 
    public A (Type depedentType) 
    { 
    } 
} 

public class B : IB 
{ 
    public B (IA a) { } // dependent on A 
} 

我怎樣才能在解決時間通過B的類型A的構造函數?

回答

0

事情是這樣的:

builder.Register((c, p) => new A(p.TypedAs<Type>)).As<IA>(); 

builder.Register(c => new B(c.Resolve<IA>(TypedParameter.From(typeof(B))))).As<IB>();