If ignorance is bliss

I have a question about ignorance. Not persistence ignorance, but UI ignorance. This is, in part, a result of some thinking on my part in response to a recent thread by rushino.

In the past, my support libraries have defined a static SessionProvider class that the repositories use internally to get SessionProvider.Current. It just recently occurred to me that this ties any persistence layer built on such a mechanism to the web, as that static class uses HttpContent.Current.Items to store a session.

This is bad is it not?

So I sat down and reworked a few things. Instead of a static class, my support libraries now define only an interface, ISessionProvider, which must now be injected into repository constructors. The benefit here is that now it doesn’t care how or where the session is stored.

This affected my unit of work implementation though. It could no longer make use of the static class, and required I inject ISessionProvider into it’s constructor as well. Which left an action that uses transactions looking more like the following:


[HttpPost]
public ActionResult DoSomething(DoSomethingModel model)
{
 
using (var worker = DependancyResolver.Current.GetService<IUnitOfWork>())
{
// actually do something...
}
 
return View();
 
}

Of course, I could simply create a static UnitOfWorkFactory class in the UI project to wrap calls to the resolver, but I can’t help feel there is a better way out there that I am not aware of.

Any thoughts?

Sadly, this is still a topic that is over my head. But I was at a user group meeting last night where the speaker was talking about entity framework and making all your code data and UI independent.

You might look at this code sample here.

http://devlinliles.com/post/Houston-DNUG-Presentation.aspx (it contains code and a powerpoint)

Hey DK. Thanks very much for responding. I am quite familiar with EF CTP5, having contributed to the project myself. My issue here, however, was more about dependency resolution than it was about persisting entities. In the time since I posted this, I’ve found a resolution.

=)