在Startup.cs中访问Ninject

时间:2014-03-26 16:15:53

标签: .net oauth ninject owin

是否可以在startup.cs(Owin)中访问ninject?

我在startup.cs中初始化OAuth并创建自定义AuthenticationProvider。

public partial class Startup
    {
        [Inject]
        public IOAuthAuthorizationServerProvider AuthorizationProvider { set; private get; }


        public void ConfigureAuth(IAppBuilder app)
        {

            app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions()
            {
                TokenEndpointPath = new PathString("/internal/token"),
                Provider = AuthorizationProvider,
                AuthenticationMode = AuthenticationMode.Active,
                AllowInsecureHttp = true
            });

            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions()
            {
                AuthenticationType = "Bearer",
                AuthenticationMode = AuthenticationMode.Active
            });
        }
    }

Saldy ninject无法注入AuthorizationProvider,因为owin会创建启动实例。如何为OAuth授权提供程序注入depdendencies?

我在“App_Start”中实例化ninject - > NinjectWebCommon.cs就像脚手架创建的那样。

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(NinjectWebCommon), "Start")]
[assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(NinjectWebCommon), "Stop")]

namespace Qvg.Pflanzenlexikon.WebPortal
{
    public static class NinjectWebCommon 
    {
...

0 个答案:

没有答案