entity framework - Autofac registration with multiple assembies and differing EntityConnections -


we have 2 assemblies contain own entity-framework edmx & repositoriy objects. these registered using autofac in asp.net webapplication.

these assemblies similar of architecture (but differing edmx) have found last entityconnection being registered entityconnection being used in both assemblies. need limit usage of entityconnection used types of assembly or namespace.

var assembly = typeof(activity).assembly; builder.registerassemblytypes(assembly).asimplementedinterfaces(); builder.register(reg => new entityconnection(connectionstring));  var assembly = typeof(user).assembly; builder.registerassemblytypes(assembly).asimplementedinterfaces(); builder.register(reg => new entityconnection(connectionstring)); 

is there way register entityconnection , limit depth of entityconnection? limit each entityconnection assembly belong to?

here's pseudocode example of how want register entityconnection use in assembly or namespace.

builder.register(reg => new entityconnection(connectionstring)).fornamespace("x"); 

try solve problem @ higher level of abstraction. since have 2 separate domains (one containing activity entity, , 1 containing user entity), convenient have explicitly in application design. instance, define factory of kind per domain:

public interface iactivitydomaincontextfactory {     objectcontext createnew(); }  public interface ipeopledomaincontextfactory {     objectcontext createnew(); } 

you can create implementation each interface, register them in autofac containerbuilder , let services depend on 1 of interfaces, instead of depending them on entityconnection.

in case of course still have dependency on entity framework (see here how abstract away), makes configuration easier, less fragile, better performing, , application code more maintainable.

i hope helps.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -