1
我有問題,因爲我的容器在我的global.asax中註冊時沒有被調用,所以我認爲這可能是因爲我現在正在使用OWIN啓動類。我已經將容器的實例化現在移到了這個類中。我不知道這是否是適當的:當使用OWIN啓動類時,如何在註冊我的依賴關係後處理Castle Windsor容器?
[assembly: OwinStartup(typeof(Startup))]
namespace Namespace.WebApi
public class Startup : IDisposable
{
private readonly WindsorContainer _Container;
public Startup()
{
_Container = new WindsorContainer();
_Container.Install(FromAssembly.Named("Namespace.WebApi.Installers"));
}
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
config.Services.Replace(typeof(IHttpControllerActivator),
new WindsorHttpControllerActivator(_Container));
/// other configuration
}
public void Dispose()
{
_Container.Dispose();
}
}
工作過!更喜歡這種方法,而不是整個創業。一次性 – Braydie