![]() |
VOOZH | about |
dotnet add package Autofac.Wcf --version 7.0.0
NuGet\Install-Package Autofac.Wcf -Version 7.0.0
<PackageReference Include="Autofac.Wcf" Version="7.0.0" />
<PackageVersion Include="Autofac.Wcf" Version="7.0.0" />Directory.Packages.props
<PackageReference Include="Autofac.Wcf" />Project file
paket add Autofac.Wcf --version 7.0.0
#r "nuget: Autofac.Wcf, 7.0.0"
#:package Autofac.Wcf@7.0.0
#addin nuget:?package=Autofac.Wcf&version=7.0.0Install as a Cake Addin
#tool nuget:?package=Autofac.Wcf&version=7.0.0Install as a Cake Tool
Windows Communication Foundation (WCF) integration for Autofac.
Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.
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);
}
}
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" %>
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 Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net472 net472 is compatible. net48 net48 was computed. net481 net481 was computed. |
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 |
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 | 362,939 | 1/27/2024 |
| 6.1.0 | 420,187 | 7/18/2022 |
| 6.0.0 | 671,426 | 10/4/2020 |
| 5.0.0 | 565,955 | 1/30/2020 |
| 4.1.0 | 1,344,468 | 5/24/2018 |
| 4.0.0 | 1,202,511 | 9/11/2015 |
| 3.0.2 | 132,129 | 6/17/2015 |
| 3.0.1 | 432,918 | 3/27/2014 |
| 3.0.0 | 167,598 | 1/30/2013 |
| 3.0.0-beta2 | 2,245 | 12/23/2012 |
| 3.0.0-beta | 2,415 | 11/1/2012 |
| 2.6.3.862 | 217,279 | 6/20/2012 |
| 2.6.2.859 | 4,545 | 6/7/2012 |
| 2.6.1.841 | 16,072 | 3/5/2012 |
| 2.5.2.830 | 9,971 | 8/12/2011 |
| 2.5.1.827 | 5,504 | 7/10/2011 |
| 2.4.5.724 | 8,152 | 3/12/2011 |
| 2.4.4.705 | 5,234 | 2/6/2011 |
| 2.4.3.700 | 4,998 | 1/30/2011 |
| 2.4.2.696 | 6,206 | 1/24/2011 |
Release notes are at https://github.com/autofac/Autofac.Wcf/releases