Tag: ninject owin

为什么要处理ASP.NET Web Api的依赖性解析器?

我有一个自定义IDependencyResolver : internal class NinjectResolver : IDependencyResolver { private IKernel _kernel; internal NinjectResolver(params ApplicationModule[] modules) { _kernel = new StandardKernel(modules); } public IDependencyScope BeginScope() { return this; } public object GetService(Type serviceType) { return _kernel.TryGet(serviceType); } public IEnumerable GetServices(Type serviceType) { return _kernel.GetAll(serviceType); } protected void Dispose(bool disposing) { if(disposing) { if(_kernel != null && […]

Ninject不解析OWIN的依赖关系

public class WebAppHost { public WebAppHost(IAppSettings appSettings) { this._appSettings = appSettings; } public Configuration(IAppBuilder appBuilder) { if(this._appSettings.StartApi) appBuilder.UseWebApi(); } } public class AppContext { public static void Start(string[] args) { DynamicModule.Utility.RegisterModule(typeof(OnePerRequestHttpModule)); DynamicModule.Utility.RegisterModule(typeof(NinjectHttpModule)); _bootstrapper.Initialize(CreateKernel); WebApp.Start(“uri”); } private static IKernel CreateKernel() { var kernel = new StandardKernel(); kernel.bind<Func>().ToMethod(ctx => () => new Bootstrapper().Kernel); kernel.bind().To(); RegisterServices(kernel); return kernel; […]

如何在WebApi OwinHost启动中使用Ninject引导程序?

我正在从IIS WebAPI迁移到OwinHost。 利用nuget软件包的最新预发布版本,我在这里成功使用了说明: https://github.com/ninject/Ninject.Web.Common/wiki/Setting-up-a-OWIN-WebApi-application 这是我的代码的存根: public void Configuration(IAppBuilder app) { var config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); app.UseNinjectMiddleware(CreateKernel); app.UseNinjectWebApi(config); } private static StandardKernel CreateKernel() { var kernel = new StandardKernel(); kernel.Load(Assembly.GetExecutingAssembly()); RegisterServices(kernel); return kernel; } private static void RegisterServices(IKernel kernel) { … } 但是在我的代码和文档示例中,Ninject内核直到启动后才会创建。 但是,我需要在Cors和OAuth中间件注册的启动注册过程中使用Ninject DI。 在迁移到OwinHost之前,我可以这样做: public void Configuration(IAppBuilder app) { _bootstrapper = new Bootstrapper(); […]