Skip to content

Simplify.DI.Wcf

Alexanderius edited this page Jan 23, 2021 · 3 revisions

Simplify.DI.Wcf Documentation

Provides ability to use Simplify.DI as IOC container for WCF services.

Available at NuGet as binary package

Adding Simplify.DI.Wcf to WCF pipeline

To use Simplify.DI.Wcf please add Factory="Simplify.DI.Wcf.SimplifyServiceHostFactory" to your WCF service *.svc file.

Service.svc file example:

<%@ ServiceHost Language="C#" Debug="true" Service="MyNamespace.Service"
CodeBehind="Service.svc.cs" Factory="Simplify.DI.Wcf.SimplifyServiceHostFactory" %>

IOC registrations

Simplify.DI registrations should be done via global.asax.cs file (you need to create Global.asax and Global.asax.cs files if you don't have)

Examples

Global.asax
<%@ Application Codebehind="Global.asax.cs" Inherits="MyService.Global" Language="C#" %>
Global.asax.cs
using System;
using Simplify.DI;

namespace MyService
{
	public class Global : System.Web.HttpApplication
	{
		protected void Application_Start(object sender, EventArgs e)
		{
			DIContainer.Current.Register<ISomeInterface, ISomeClass>();
		}
	}
}

Usage example

Then you can use DI for your service class:

IService.cs
using System.ServiceModel;

namespace MyService
{
	[ServiceContract]
	public interface IService
	{
		[OperationContract]
		void MyMethod();
	}
}
Service.svc.cs
using System;

namespace MyService
{
	public class Service : IService
	{
		public Service(ISomeInterface dependency)
		{
		}

		public void MyMethod()
		{
		}
	}
}