Autofac.Mvc5.Owin 6.1.0

Prefix Reserved
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 and Polyglot Notebooks. 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 Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
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 184,249 8/23/2022
6.0.0 556,869 10/5/2020
5.0.0 328,871 1/31/2020
4.0.1 1,415,676 2/8/2017
4.0.0 204,937 8/10/2016
4.0.0-rc3-217 2,141 7/25/2016
3.1.0 332,698 8/21/2014
3.0.1 4,361 6/20/2014
3.0.0 2,137 6/20/2014
3.0.0-alpha3 1,314 3/27/2014
3.0.0-alpha2 1,191 3/26/2014
3.0.0-alpha 1,145 2/17/2014