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();
            }
      }

 

posted @ 2015-09-17 13:25  Yu  阅读(1357)  评论(4编辑  收藏  举报