2013-07-13 28 views
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)); 

沒有什麼太複雜。

但這是我能想到的唯一奇怪的事情。

  1. typeof(MvcApplication)是其中該代碼存在於同一個項目,在global.asax
  2. typeof(MvcApplication)在-seperate- DLL被發現,這是我經由AddReferences手動添加。

任何人看到我做錯了什麼?

+0

如果您臨時註釋掉無參數構造函數會發生什麼情況 - 使用另一個構造函數成功解析它會怎樣? –

+0

我會檢查。請保留.. –

+0

確認,與無參數ctor註釋正常工作。 –

回答

2

問題是,我的貪婪 - 正在變得叫...但如果你看着貪婪的人,你會看到我在做: this()

很蹩腳的新手錯誤。

因此,它調用貪婪的ctor,但在它進入範圍之前,它必須冒泡到另一個無參數ctor。

我一直認爲它跳過了貪婪,只是碰到無參數。

用戶和鍵盤之間的錯誤。