简体   繁体   English

具有多个LinqToSql DataContext的StructureMap

[英]StructureMap with multiple LinqToSql DataContexts

I'm on a ASP.NET MVC project and I'm using a generic repository on Data Layer. 我在ASP.NET MVC项目上,并且在数据层上使用通用存储库。

This app uses 3 differents DataContexts to manage 3 differents databases. 此应用程序使用3个不同的DataContexts来管理3个不同的数据库。

It works great so far. 到目前为止效果很好。

Now, I'm trying to archieve Unit Of Work and it's working but only if a inject a specific DataContext instance. 现在,我正在尝试归档工作单元,并且它仅在注入特定的DataContext实例时才有效。 Is there a way to inject a generic DataContext class and StructureMap instantiates the right DataContext for me? 有没有办法注入通用的DataContext类,而StructureMap为我实例化正确的DataContext?

Thanks!! 谢谢!!

Named Instances are going to be your best bet. 命名实例将是您最好的选择。 Register each context with a name representing the database, then you can resolve the correct DataContext with just a name. 用代表数据库的名称注册每个上下文,然后仅用一个名称即可解析正确的DataContext。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM