Autofac.Mvc5.Owin 6.1.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
.NET Framework 4.7.2
dotnet add package Autofac.Mvc5.Owin --version 6.1.0
NuGet\Install-Package Autofac.Mvc5.Owin -Version 6.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Autofac.Mvc5.Owin" Version="6.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Autofac.Mvc5.Owin --version 6.1.0
#r "nuget: Autofac.Mvc5.Owin, 6.1.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Autofac.Mvc5.Owin as a Cake Addin
#addin nuget:?package=Autofac.Mvc5.Owin&version=6.1.0

// Install Autofac.Mvc5.Owin as a Cake Tool
#tool nuget:?package=Autofac.Mvc5.Owin&version=6.1.0

Autofac.Mvc.Owin

OWIN support for the ASP.NET MVC integration for Autofac.

Build status

Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.

If you're working with ASP.NET Core, you want Autofac.Extensions.DependencyInjection, not this package.

Quick Start

If you are using MVC as part of an OWIN application, you need to:

public class Startup
{
  public void Configuration(IAppBuilder app)
  {
    var builder = new ContainerBuilder();

    // STANDARD MVC SETUP:

    // Register your MVC controllers.
    builder.RegisterControllers(typeof(MvcApplication).Assembly);

    // Run other optional steps, like registering model binders,
    // web abstractions, etc., then set the dependency resolver
    // to be Autofac.
    var container = builder.Build();
    DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

    // OWIN MVC SETUP:

    // Register the Autofac middleware FIRST, then the Autofac MVC middleware.
    app.UseAutofacMiddleware(container);
    app.UseAutofacMvc();
  }
}

Minor gotcha: MVC doesn't run 100% in the OWIN pipeline. It still needs HttpContext.Current and some other non-OWIN things. At application startup, when MVC registers routes, it instantiates an IControllerFactory that ends up creating two request lifetime scopes. It only happens during app startup at route registration time, not once requests start getting handled, but it's something to be aware of. This is an artifact of the two pipelines being mangled together.

Check out the Autofac ASP.NET MVC integration documentation for more information.

Get Help

Need help with Autofac? We have a documentation site as well as API documentation. We're ready to answer your questions on Stack Overflow or check out the discussion forum.

Product Versions
.NET Framework net472 net48
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Autofac.Mvc5.Owin:

Package Downloads
bscheiman.Common.Aspnet

Useful extensions/tools/utils I keep using all over the place. Hit me up (@bscheiman) if you need help.

Inovout.Web.Mvc-KuaJing

support OWIN

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Autofac.Mvc5.Owin:

Repository Stars
NuGet/NuGetGallery
NuGet Gallery is a package repository that powers https://www.nuget.org. Use this repo for reporting NuGet.org issues.
Version Downloads Last updated
6.1.0 8,985 8/23/2022
6.0.0 297,873 10/5/2020
5.0.0 200,488 1/31/2020
4.0.1 1,149,913 2/8/2017
4.0.0 165,440 8/10/2016
4.0.0-rc3-217 1,874 7/25/2016
3.1.0 301,851 8/21/2014
3.0.1 3,941 6/20/2014
3.0.0 1,630 6/20/2014
3.0.0-alpha3 1,170 3/27/2014
3.0.0-alpha2 1,027 3/26/2014
3.0.0-alpha 999 2/17/2014