您的位置:首页 > 大数据 > 人工智能

The service ‘xxx’ configured for WCF is not registered with the Autofac container

2015-09-17 13:25 2381 查看
最近在使用autofac.wcf时,报如下异常:

Exception Details: System.InvalidOperationException: The service 'xxx' configured for WCF is not registered with the Autofac container.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

原:

public static class Initializer
{
public static void Initialize()
{
RegisterTypes();
Bootstrapper.With.AutoMapper().Start();
}

static void RegisterTypes()
{
ContainerBuilder builder = new ContainerBuilder();

builder.RegisterType<UnitOfWork>();
builder.RegisterType<PermissionDbContext>().As<IDbContext>();
builder.RegisterType<PermissionService>().As<IPermissionService>();
builder.RegisterType<UnitOfWork>().As<IUnitOfWork>();
AutofacHostFactory.Container = builder.Build();
}
}


改:

public static class Initializer
{
public static void Initialize()
{
RegisterTypes();
Bootstrapper.With.AutoMapper().Start();
}

static void RegisterTypes()
{
ContainerBuilder builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly());
builder.RegisterType<UnitOfWork>();
builder.RegisterType<PermissionDbContext>().As<IDbContext>();
builder.RegisterType<PermissionService>().As<IPermissionService>();
builder.RegisterType<UnitOfWork>().As<IUnitOfWork>();
AutofacHostFactory.Container = builder.Build();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: