-
-
Notifications
You must be signed in to change notification settings - Fork 9
Simplify.DI.Wcf
Alexanderius edited this page Dec 15, 2022
·
4 revisions
Provides ability to use Simplify.DI as IOC container for WCF services.
Available at NuGet as binary package
To use Simplify.DI.Wcf please add Factory="Simplify.DI.Wcf.SimplifyServiceHostFactory" to your WCF service *.svc file.
<%@ ServiceHost Language="C#" Debug="true" Service="MyNamespace.Service"
CodeBehind="Service.svc.cs" Factory="Simplify.DI.Wcf.SimplifyServiceHostFactory" %>
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)
<%@ Application Codebehind="Global.asax.cs" Inherits="MyService.Global" Language="C#" %>
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, SomeClass>();
}
}
}
Then you can use DI for your service class:
using System.ServiceModel;
namespace MyService
{
[ServiceContract]
public interface IService
{
[OperationContract]
void MyMethod();
}
}
using System;
namespace MyService
{
public class Service : IService
{
public Service(ISomeInterface dependency)
{
}
public void MyMethod()
{
}
}
}