Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
1. Autofac is nothing but an open-source dependency injection (DI) or inversion of control (IoC) container developed on Google Code.Its similar to Ninject or other IOC.
I don't know what difficulty you are getting in WCF self hosting by MVC5 using Autofac.I think you can do like as given below example for WEBAPI :
Configured Autofac with ASP.Net MVC4 and WebAPI. Here are the steps required to configure Autofac
Install package Autofac.MVC4
Install package Autofac.WebApi
Add a class AutofacBootstrap. Use this class to configure the dependencies within your project.
public class AutofacBootstrap
{
internal static void Init(ContainerBuilder builder)
{
}
}
Open Global.asax file and add a method like
private void RegisterIOC()
{
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.RegisterApiControllers(typeof(MvcApplication).Assembly);
AutofacBootstrap.Init(builder);
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
GlobalConfiguration.Configuration.DependencyResolver = new Autofac.Integration.WebApi.AutofacWebApiDependencyResolver(container);
}
Call the method from Application_Start
Its done.
B> There is a drawback and advantages of self hosting WCF with in a project or IIS.
Self-Hosting :
Needs to add code to host the process.
Host process should be running before client makes a call to the service.
Automatic process recycling not possible.
Can controlled the service lifetime using Open and Close methods.
Easy to deploy.
IIS Hosting :
Automatic hosting.
IIS host runs automatically when a client makes a call to the service.
Automatic process recycling possible.
Lifetime cannot be controlled manually.
More difficult deployment than Self-Hosting.
Let me know if you have any concern i will try to create sample project in MVC5 with Autofac for you.