Oct 1, 2008 at 3:50 PM
Does it make sense to instantiate an the Entity Framework Model with Unity so one does have access to the SAME instance all the time. Does any one do it?

I tried but since the model does have 3 constructor it does not work on the first try (probably there is a way to say I want to use the default constructor), would I need to write a wrapper?

I have written a wrapper and the wrapper takes care of the connect string, but when I change the connect string, Entity Framework does complain...

Any thoughts on this?
Thankx, Harry
Oct 2, 2008 at 7:07 PM
[iwhp1] does anyone do it?

Not yet but sounds like a great idea when I do.

[whp1] I want to use default constructor

On my Sept 27, 9:35 response I provide a demo and details for an extension I wrote that will tell Unity to use the default constructor - the link follows:

What is the complaint the EF gives when you attempt to change the connection string - and how are you changing it?   I can see where we'll want to get around this...
Oct 6, 2008 at 8:08 PM
We use this approach in our ASP.NET application. I have created own constructor for our entity model which takes two parameters - connection string name and container name. The entity model is then registered into Unity container with these constructor and uses our own lifetime manager which utilize context to store the entity model instance. It works like charm!
Jan 14, 2010 at 5:53 AM

Hello Harry/iwhp1,

You've an interesting question here, I was thinking about the same, but your statement 'access to the SAME instance all the time', can be dangerous because of multithreading?
What happens when two users (userA & userB in a asp.net web-application) are accessing the same instance?

Please share your thoughts...






Feb 10, 2010 at 6:41 AM

Hi Stef

We were building a WPF application, so I cannot say much about ASP.NET. In the WPF application we are using the above scenario and it works quite well. There are some issues when another user is changing data on another computer, then the entity model data gets out of sync, but that seems to be a design issue and we use the .Refresh() method to get updated records. Another issue is performance, since we keep quite a lot of data form the database in the WPF client and do some heavy stuff on the entities (quite lots and deep relationships).

So for ASP.NET I have not done anything explicitly with Entity Framework and handling the connecction. We have done some .NET RIA Services stuff and the performance with the default behavior is OK and we do not have any issues. We are not using any kind of Unity stuff.

Cheers Harry