This commit is contained in:
Eugene Sadovoi 2020-05-14 13:38:56 -07:00
Родитель ee644edd47
Коммит a9f9799817
1 изменённых файлов: 16 добавлений и 3 удалений

Просмотреть файл

@ -3,19 +3,19 @@
[![NuGet](https://img.shields.io/nuget/dt/Unity.wcf.svg)](https://www.nuget.org/packages/Unity.wcf)
[![NuGet](https://img.shields.io/nuget/v/Unity.wcf.svg)](https://www.nuget.org/packages/Unity.wcf)
# Unity.Wcf
Unity.Wcf is a library that allows simple Integration of Microsoft's Unity IoC container with WCF. This project includes a bespoke `InstanceProvider` that creates a child container per client connection and disposes of all registered `IDisposable` instances once the connection is terminated.
## How to use Unity.Wcf
*WAS hosted services*
### WAS hosted services
For WAS-based hosting, first create a WcfServiceFactory `class`. You can choose any name.
The WcfServiceFactory has to extend the `UnityServiceHostFactory` and implement the `ConfigureContainer` method.
Open the WcfServiceFactory class. Add all necessary component registrations. If you are registering `IDisposable` components that need to be created and destroyed on a per client basis (i.e. an EntityFramework DataContext), please ensure that you use the `HierarchicalLifetimeManager`:
```cs
public class WcfServiceFactory : UnityServiceHostFactory {
protected override void ConfigureContainer(IUnityContainer container) {
@ -29,6 +29,7 @@ public class WcfServiceFactory : UnityServiceHostFactory {
```
Right click on your svc file in the solution explorer and select View Markup. Next replace `CodeBehind="Service1.svc.cs"` with `Factory="WcfService1.WcfServiceFactory"`, where `WcfService1` is the namespace of your project. If you are using fileless activation and do not have an SVC file, change your web.config instead.
```xml
<serviceHostingEnvironment>
<serviceActivations>
@ -37,8 +38,20 @@ Right click on your svc file in the solution explorer and select View Markup. Ne
<serviceHostingEnvironment>
```
*Windows Service hosting*
### Windows Service hosting
If you are hosting your WCF service within a Windows Service using a `ServiceHost`, replace the `ServiceHost` instance with the custom `Unity.Wcf.UnityServiceHost`. You will find that the `UnityServiceHost` takes in a Unity container as its first parameter but is otherwise identical to the default `ServiceHost`.
You are free to configure Unity any way you like as long as the configured container is passed into the `UnityServiceHost` correctly. As with WAS hosting, if you want Unity.WCF to dispose of `IDisposable` components, you must register those components using the `HierarchicalLifetimeManager` lifestyle.
## Code of Conduct
This project has adopted the code of conduct defined by the [Contributor Covenant](https://www.contributor-covenant.org/) to clarify expected behavior in our community. For more information, see the [.NET Foundation Code of Conduct](https://www.dotnetfoundation.org/code-of-conduct)
## Contributing
See the [Contributing guide](https://github.com/unitycontainer/unity/blob/master/CONTRIBUTING.md) for more information.
## .NET Foundation
Unity Container is a [.NET Foundation](https://dotnetfoundation.org/projects/unitycontainer) project