Register autofac in windows service project

user1096760

I want to use autofac in my project for windows service but I get this error:

"The requested service 'InsideView.Business.Services.BusinessServiceFactory' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency."

My code:

       var builder = new ContainerBuilder();

       foreach (var type in typeof(IMyService).Assembly.GetTypes().Where(type => type.Name.EndsWith("Service") && type.IsClass))
        {
            var siblingInterface = type.GetInterfaces().First(i => i.Name == "I" + type.Name);
            builder.RegisterType(type).Keyed(siblingInterface, typeof(IBusinessService)).InstancePerLifetimeScope();
        }

        builder.RegisterType<BusinessServiceFactory>()
            .As<IBusinessServiceFactory>().InstancePerLifetimeScope();


        IContainer container = builder.Build();

       var businessFactory = container.Resolve<BusinessServiceFactory>()

Any ideas? Thanks

Peter Lillevold

When you have registered the service as IBusinessServiceFactory you must also resolve for IBusinessServiceFactory, not the class type BusinessServiceFactory as you are doing in the sample.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Register application lifetime scoped service with Autofac in ASP.NET Core

From Dev

Register application lifetime scoped service with Autofac in ASP.NET Core

From Dev

Autofac - Register multiple decorators

From Dev

Autofac register assembly types

From Dev

Autofac register and resolve with Names

From Dev

Autofac register interface MediatR

From Dev

Register with object with AutoFac

From Dev

Register Int as KeyFilter with autofac

From Dev

How to register circular type in Autofac?

From Dev

Register Container Itself Using Autofac

From Dev

Automatically register interface to class in autofac

From Dev

Automatically register interface to class in autofac

From Dev

Autofac Register Generic Delegate factory

From Dev

Register ISecureDataFormat<AuthenticationTicket> using Autofac

From Dev

How to register a windows service but avoid it being listed in the services console?

From Dev

The type '***' is not assignable to service '***' in Autofac

From Dev

The type '***' is not assignable to service '***' in Autofac

From Dev

Injecting an instance of a service with Autofac

From Dev

Start windows service on install without setup project

From Dev

It is possible to add Windows Service to an Existing project?

From Dev

Pycharm background for project tree and other service windows

From Dev

ServiceStack as Windows Service with Razor - Setup Project

From Dev

How to integrate topshelf to an existing windows service project?

From Dev

Windows service uses external libraries, do I need to somehow register those with the service?

From Dev

Autofac: register generic type with nongeneric interface

From Dev

How to register a type with autofac after container creation

From Java

How do I Register Autofac Module with Configuration

From Dev

Register action with Autofac per application start

From Dev

Unable to register and add automapper profile in Autofac

Related Related

  1. 1

    Register application lifetime scoped service with Autofac in ASP.NET Core

  2. 2

    Register application lifetime scoped service with Autofac in ASP.NET Core

  3. 3

    Autofac - Register multiple decorators

  4. 4

    Autofac register assembly types

  5. 5

    Autofac register and resolve with Names

  6. 6

    Autofac register interface MediatR

  7. 7

    Register with object with AutoFac

  8. 8

    Register Int as KeyFilter with autofac

  9. 9

    How to register circular type in Autofac?

  10. 10

    Register Container Itself Using Autofac

  11. 11

    Automatically register interface to class in autofac

  12. 12

    Automatically register interface to class in autofac

  13. 13

    Autofac Register Generic Delegate factory

  14. 14

    Register ISecureDataFormat<AuthenticationTicket> using Autofac

  15. 15

    How to register a windows service but avoid it being listed in the services console?

  16. 16

    The type '***' is not assignable to service '***' in Autofac

  17. 17

    The type '***' is not assignable to service '***' in Autofac

  18. 18

    Injecting an instance of a service with Autofac

  19. 19

    Start windows service on install without setup project

  20. 20

    It is possible to add Windows Service to an Existing project?

  21. 21

    Pycharm background for project tree and other service windows

  22. 22

    ServiceStack as Windows Service with Razor - Setup Project

  23. 23

    How to integrate topshelf to an existing windows service project?

  24. 24

    Windows service uses external libraries, do I need to somehow register those with the service?

  25. 25

    Autofac: register generic type with nongeneric interface

  26. 26

    How to register a type with autofac after container creation

  27. 27

    How do I Register Autofac Module with Configuration

  28. 28

    Register action with Autofac per application start

  29. 29

    Unable to register and add automapper profile in Autofac

HotTag

Archive