Autofac.Wcf 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.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, C# scripting and .NET Interactive. 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 Versions
.NET Framework net472 net48
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.7.2

NuGet packages (14)

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

Package Downloads
Zen.Core.Host

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

Autofac.Multitenant.Wcf The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

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 The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

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

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
6.1.0 19,484 7/18/2022
6.0.0 286,465 10/4/2020
5.0.0 250,646 1/30/2020
4.1.0 753,590 5/24/2018
4.0.0 812,883 9/11/2015
3.0.2 81,941 6/17/2015
3.0.1 268,726 3/27/2014
3.0.0 110,982 1/30/2013
3.0.0-beta2 1,222 12/23/2012
3.0.0-beta 1,422 11/1/2012
2.6.3.862 91,165 6/20/2012
2.6.2.859 2,063 6/7/2012
2.6.1.841 7,188 3/5/2012
2.5.2.830 6,334 8/12/2011
2.5.1.827 2,719 7/10/2011
2.4.5.724 5,346 3/12/2011
2.4.4.705 2,192 2/6/2011
2.4.3.700 2,262 1/30/2011
2.4.2.696 2,985 1/24/2011