5
我想使用Autofac在中找到最貪婪的構造函數 dll。Autofac沒有找到最貪婪的構造函數
它沒有找到它,只能找到一個無參數的構造函數。
這是兩個構造函數:
public SimpleAuthenticationController() { .. }
public SimpleAuthenticationController(IAuthenticationCallbackProvider callbackProvider) : this()
現在,我這是怎麼註冊的東西與autofac
:
var builder = new ContainerBuilder();
builder.RegisterType<SampleMvcAutoAuthenticationCallbackProvider>().As<IAuthenticationCallbackProvider>();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.RegisterControllers(typeof(SimpleAuthenticationController).Assembly);
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
沒有什麼太複雜。
但這是我能想到的唯一奇怪的事情。
typeof(MvcApplication)
是其中該代碼存在於同一個項目,在global.asax
typeof(MvcApplication)
在-seperate- DLL被發現,這是我經由AddReferences
手動添加。
任何人看到我做錯了什麼?
如果您臨時註釋掉無參數構造函數會發生什麼情況 - 使用另一個構造函數成功解析它會怎樣? –
我會檢查。請保留.. –
確認,與無參數ctor註釋正常工作。 –