Autofac.Wcf 6.1.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Autofac.Wcf --version 6.1.0                
NuGet\Install-Package Autofac.Wcf -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.Wcf" Version="6.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Autofac.Wcf --version 6.1.0                
#r "nuget: Autofac.Wcf, 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.Wcf as a Cake Addin
#addin nuget:?package=Autofac.Wcf&version=6.1.0

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

Autofac.Wcf

Windows Communication Foundation (WCF) integration for Autofac.

Build status

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

Quick Start: Clients

During application startup, for each service register a ChannelFactory<T> and a function that uses the factory to open channels:

var builder = new ContainerBuilder();

// Register the channel factory for the service. Make it
// SingleInstance since you don't need a new one each time.
builder
  .Register(c => new ChannelFactory<ITrackListing>(
    new BasicHttpBinding(),
    new EndpointAddress("http://localhost/TrackListingService")))
  .SingleInstance();

// Register the service interface using a lambda that creates
// a channel from the factory. Include the UseWcfSafeRelease()
// helper to handle proper disposal.
builder
  .Register(c => c.Resolve<ChannelFactory<ITrackListing>>().CreateChannel())
  .As<ITrackListing>()
  .UseWcfSafeRelease();

// You can also register other dependencies.
builder.RegisterType<AlbumPrinter>();

var container = builder.Build();

When consuming the service, add a constructor dependency as normal. This example shows an application that prints a track listing to the console using the remote ITrackListing service. It does this via the AlbumPrinter class:

public class AlbumPrinter
{
  readonly ITrackListing _trackListing;

  public AlbumPrinter(ITrackListing trackListing)
  {
    _trackListing = trackListing;
  }

  public void PrintTracks(string artist, string album)
  {
    foreach (var track in _trackListing.GetTracks(artist, album))
      Console.WriteLine("{0} - {1}", track.Position, track.Title);
  }
}

Quick Start: Services

To get Autofac integrated with WCF on the service side you need to reference the WCF integration NuGet package, register your services, and set the dependency resolver. You also need to update your .svc files to reference the Autofac service host factory.

Here’s a sample application startup block:

protected void Application_Start()
{
  var builder = new ContainerBuilder();

  // Register your service implementations.
  builder.RegisterType<TestService.Service1>();

  // Set the dependency resolver.
  var container = builder.Build();
  AutofacHostFactory.Container = container;
}

And here’s a sample .svc file.

<%@ ServiceHost
    Service="TestService.Service1, TestService"
    Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>

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.
  • .NETFramework 4.7.2

NuGet packages (15)

Showing the top 5 NuGet packages that depend on Autofac.Wcf:

Package Downloads
Zen.Core.Host

Модуль Zen.Core предназначенный для автоматического хостинга приложений и вебсервисов в консольном и сервисном режимах

Autofac.Multitenant.Wcf

Multitenant applications allow individual tenants to override dependencies rather than having a simple root container for everyone. This extension provides support for an application container and tenant-specific overrides using Autofac when hosting WCF services.

Autofac.Extras.Multitenant.Wcf

Multitenant applications allow individual tenants to override dependencies rather than having a simple root container for everyone. This extension provides support for an application container and tenant-specific overrides using Autofac when hosting WCF services.

ImcFramework.Core

core

IME.WCF.SecurityFramework.Authentication

Package Description

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Autofac.Wcf:

Repository Stars
autofac/Examples
Example projects that consume and demonstrate Autofac IoC functionality and integration
dotnet-architecture/grpc-for-wcf-developers
gRPC for WCF Developers guidance samples
Version Downloads Last updated
7.0.0 64,111 1/27/2024
6.1.0 257,008 7/18/2022
6.0.0 526,626 10/4/2020
5.0.0 440,084 1/30/2020
4.1.0 1,070,259 5/24/2018
4.0.0 1,015,160 9/11/2015
3.0.2 117,615 6/17/2015
3.0.1 358,668 3/27/2014
3.0.0 140,101 1/30/2013
3.0.0-beta2 1,719 12/23/2012
3.0.0-beta 1,914 11/1/2012
2.6.3.862 169,815 6/20/2012
2.6.2.859 3,297 6/7/2012
2.6.1.841 12,189 3/5/2012
2.5.2.830 7,888 8/12/2011
2.5.1.827 4,189 7/10/2011
2.4.5.724 6,790 3/12/2011
2.4.4.705 3,787 2/6/2011
2.4.3.700 3,702 1/30/2011
2.4.2.696 4,633 1/24/2011