ASP.NET Classic OWIN StartUp ConfigureServices未调用 [英] ASP.NET Classic OWIN StartUp ConfigureServices not called

查看:98
本文介绍了ASP.NET Classic OWIN StartUp ConfigureServices未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个ASP.NET Classic WebAPI应用程序.我已经实现了OWIN StartUp类,并且执行了Caonfiguration方法,但是未执行ConfigureServices方法.我知道这适用于DotNetCore.

I am writing a ASP.NET Classic WebAPI application. I have implemented the OWIN StartUp class, and the Caonfiguration method is executed, however, the ConfigureServices method does not get executed. I know this works for DotNetCore.

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Owin;
using Owin;


[assembly: OwinStartup(typeof(ClassicWebApi.Startup))]

namespace ClassicWebApi
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            //CODE IS NOT EXECUTED
        }
        public void Configuration(IAppBuilder app)
        {
            //CODE IS EXECUTED
        }


    }
}

这仅是DotNetCore的功能吗,还是我需要在设置中包括另一个库?

Is this only a feature of DotNetCore or do I need to include another library in the set up?

推荐答案

我想使用依赖注入.具体来说 AddDbContext和AddScoped

I'd like to use the dependency injection. Specifically the AddDbContext and AddScoped

内置依赖项注入仅在ASP.NET Core中可用.您将需要使用第三方IoC容器,例如-

Build-in dependency injection is only available in ASP.NET Core. You will need to use third party IoC container such as -

  • Autofac for Web API
  • Ninject

这篇关于ASP.NET Classic OWIN StartUp ConfigureServices未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆