我有一段时间试图让它发挥作用。
我希望 Autofac 管理我的 WCF 服务并使用无扩展服务。
任何想法为什么这不起作用?
namespace SAIF.Services.WCF.Host
{
using System;
using System.ServiceModel.Activation;
using System.Web;
using System.Web.Routing;
using Autofac;
using Autofac.Integration.Wcf;
using SAIF.Core.Domain;
using SAIF.Core.Domain.Model;
using SAIF.Repositories;
using SAIF.Services.WCF.Core;
using SAIF.Services.WCF.Services;
public class Global : HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
// Create Routes
var factory = new AutofacServiceHostFactory();
RouteTable.Routes.Add(new ServiceRoute("FileService", factory, typeof(SAIF.Services.WCF.Core.IFileService)));
RouteTable.Routes.Add(new ServiceRoute("WebContext", factory, typeof(SAIF.Services.WCF.Core.IWebContextService)));
// Autofac Config
var builder = new ContainerBuilder();
builder.Register(x => new EFUnitOfWork())
.As<EFUnitOfWork>()
.As<IUnitOfWork>();
builder.RegisterGeneric(typeof(Repository<>))
.As(typeof(IRepository<>));
builder.Register(x => new FileService())
.As<IFileService>();
builder.Register(x => new WebContextService(x.Resolve<IRepository<WebContextItem>>(), x.Resolve<IUnitOfWork>()))
.As<IWebContextService>();
AutofacHostFactory.Container = builder.Build();
}
}
}