我遇到了问题,即在我的 global.asax 中注册时我的容器没有被调用,所以我认为这可能是因为我现在正在使用 OWIN 启动类。我现在已经将容器的实例化移到了这个类中。我想知道这样做是否合适:
[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();
}
}
最佳答案
您可以包含 Owino NuGet 打包并使用 RegisterForDisposal
扩展,如下所示:
public void Configuration(IAppBuilder app)
{
/// (...)
app.RegisterForDisposal(_Container);
}
或者你可以看看how the method is implemented并自行实现。
关于c# - 使用 OWIN 启动类时,如何在注册我的依赖项后处理我的 CaSTLe Windsor 容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41944879/