0

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?

Yuck
  • 49,664
  • 13
  • 105
  • 135
  • I'd like to add that I was previously using Ninject instead of Unity (customer-directed change). When I was using Ninject the application(s) performed as I would like them to - both seeing each other's modifications. Perhaps Ninject was refershing itself per request? Is that something I can configure Unity to do? – Yuck Apr 25 '11 at 14:48

2 Answers2

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.

Community
  • 1
  • 1
Thomas Li
  • 3,358
  • 18
  • 14
  • Right, I've considered adding a WCF service that the web app and SSIS could use in common. Just seems like there should be an easier way for LINQ to be informed that its context out-of-date. I don't think I'll ever be able to fully get away from admin-type users making data changes through SSMS. – Yuck Apr 25 '11 at 14:35
  • This is an acceptable solution and based on my wording I can see why you suggested it. I chose to go another way as I explain in the answer I posted. I'm upvoting as what you provided is helpful and would solve the problem. – Yuck Apr 25 '11 at 15:45
1

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.

Community
  • 1
  • 1
Yuck
  • 49,664
  • 13
  • 105
  • 135