Last active
August 17, 2020 00:00
-
-
Save smaglio81/fd6afa656f2e008af2b885827643418b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using System.Web; | |
using System.Web.Http; | |
using System.Web.Http.Controllers; | |
using System.Web.Http.Dependencies; | |
using System.Web.Http.ExceptionHandling; | |
using System.Web.Http.Filters; | |
using System.Web.Mvc; | |
using System.Web.Optimization; | |
using System.Web.Routing; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.DependencyInjection.Extensions; | |
using DependencyInjection.AspNet.WebApi; | |
using IDependencyResolver = System.Web.Http.Dependencies.IDependencyResolver; | |
using IExceptionFilter = System.Web.Http.Filters.IExceptionFilter; | |
namespace YourNamespace | |
{ | |
/// <summary> | |
/// https://stackoverflow.com/questions/50358349/using-microsoft-extension-dependencyinjection-in-asp-net-web-api2 | |
/// </summary> | |
public class WebApiApplication : System.Web.HttpApplication | |
{ | |
protected void Application_Start() | |
{ | |
AreaRegistration.RegisterAllAreas(); | |
GlobalConfiguration.Configure(WebApiConfig.Register); | |
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); | |
RouteConfig.RegisterRoutes(RouteTable.Routes); | |
BundleConfig.RegisterBundles(BundleTable.Bundles); | |
GlobalConfiguration.Configuration.AddMicrosoftDependencyInjectionProvider(services => | |
{ | |
services.AddControllersAsServices(System.Reflection.Assembly.GetExecutingAssembly()); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment