DataContext 看不到更新
我正在使用 Unity 2.0 针对抽象存储库注册具体的 SQL Server 存储库,如下所示:
var context = new DataContext(
ConfigurationManager.ConnectionStrings["DevDB"].ConnectionString
);
this.UnityContainer
.RegisterType<AlertQueueRepository, Sql.AlertQueueRepository>(
new InjectionConstructor(context)
);
上下文在我拥有的所有其他存储库之间共享。这在应用程序中工作得很好,但是,如果其他人(SSMS 查询、SSIS 包、其他应用程序)修改了数据库,我的存储库不会意识到这一点,也不会看到更改。
这是我使用 Unity 的方式有问题吗?也许上下文存在的时间太长了?或者我需要用 LINQ 配置什么?
I am using Unity 2.0 to register a concrete SQL Server repository against an abstract repository like so:
var context = new DataContext(
ConfigurationManager.ConnectionStrings["DevDB"].ConnectionString
);
this.UnityContainer
.RegisterType<AlertQueueRepository, Sql.AlertQueueRepository>(
new InjectionConstructor(context)
);
The context is being shared across all of the other repositories that I have. This works fine within the application, however, if someone else - SSMS query, SSIS package, other application - modifies the database my repositories are unaware of this and will not see the change.
Is this an issue with the way I'm using Unity? Perhaps the contexts are hanging around too long? Or is it something I need to configure with LINQ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑以下问题的答案:多个应用程序使用一个数据库?。
如果您确实需要多个应用程序来访问/修改数据,请考虑在数据库之上构建一个层来服务所有请求。
Consider the answer to this question: Multiple application using one database?.
If you really need multiple applications to access/modify the data, consider building a layer on top of the database to service all the requests.
事实证明,这个问题与我的类似 - ASP.NET MVC 每个请求注入。
我需要做的是让每个请求注册自己的上下文,因为它具有副作用,即每次请求后上下文都会被抛出。现在我只需要考虑这种模式对性能的影响。
This question was similar to mine it turns out - ASP.NET MVC inject per request.
What I needed to do was have each request register its own context as it has the side-effect that the context gets thrown out after each request. Now I'm just left to consider the performance implications of this pattern.