Skip to content
This repository was archived by the owner on Jan 4, 2025. It is now read-only.

Latest commit

 

History

History
67 lines (43 loc) · 2.28 KB

File metadata and controls

67 lines (43 loc) · 2.28 KB

Cofoundry.Plugins.DependencyInjection.Autofac

Build status NuGet Gitter

This library is a plugin for Cofoundry. For more information on getting started with Cofoundry check out the Cofoundry repository.

Overview

Autofac is an addictive Inversion of Control container for .NET Core, ASP.NET Core, .NET 4.5.1+, Universal Windows apps, and more.

autofac.org

This library is an Autofac implementation of the Cofoundry DI system.

Bootstrapping In a Website

The Cofoundry.Plugins.DependencyInjection.AutoFac.Web can be used to bootstrap your web application, which provides the following:

  • Registers all Cofoundry and auto-registered dependencies
  • Registers the MVC, WebApi and the common service locators
  • Registers all MVC & WebApi controllers

Registration must be done before Cofoundry is initialized, i.e.

using Microsoft.Owin;
using Owin;
using Cofoundry.Plugins.DependencyInjection.AutoFac.Web;
using Cofoundry.Web;

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

namespace MySite 
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseCofoundryAutoFacIntegration();
            app.UseCofoundry();
        }
    } 
}

Bootstrapping Manually

Outside of a web scenario, you can configure your Autofac container manually and add Cofoundry registrations using the AutoFacContainerBuilder

using AutoFac;
using Cofoundry.Plugins.DependencyInjection.AutoFac;

var autoFacBuilder = new ContainerBuilder();
var cofoundryBuilder = new AutoFacContainerBuilder(autoFacBuilder);

cofoundryBuilder.Build();