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

最近在使用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();
            }
      }

 

你可能感兴趣的:(The service ‘xxx’ configured for WCF is not registered with the Autofac container)