dependency injection - How to register Services and Types that are in separate assemblies in AutoFac? -


i'm trying register 'services' autofac. services named based on convention (aggregate root + 'service') , implement interfaces same name: 'i' + servicename. example, orderservice implements iorderservice.

however, both concrete types , interfaces in separate assemblies. far have following code:

builder.registerassemblytypes(typeof(orderservice).assembly)        .where(t => t.name.endswith("service"))        .asimplementedinterfaces(); 

is best way accomplish in autofac? if of services derive abstract class?

autofac doesn't care whether interfaces in same assembly or not. registration fine, if want load 'services' several assemblies, can pass in collection of assemblies:

builder.registerassemblytypes(appdomain.currentdomain.getassemblies())    .where(t => t.name.endswith("service"))    .asimplementedinterfaces(); 

i warn class postfixes indicate srp violations, , rap violations such helper, manager, and... service. might want try different design each query , use case of such service class placed in own class , marked with generic interface. way can register implementations of same generic interface 1 single line:

builder.registerassemblytypes(     appdomain.currentdomain.getassemblies())     .asclosedtypesof(typeof(icommandhandler<>)); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -