Quantcast
Channel: patterns & practices: Project Silk
Viewing all articles
Browse latest Browse all 93

New Post: Whats controlling dbContext instances in IUnitOfWork

$
0
0
Hi,

In MileageStats the configuration for the type mappings used by Unity are set in the unity.config file (or unity.debug.config file depending your launch configuration). In that file you can find the following mapping for the IUnitOfWork interface:
<typetype="MileageStats.Data.IUnitOfWork, MileageStats.Data"mapTo="MileageStats.Data.SqlCe.MileageStatsDbContext, MileageStats.Data.SqlCe"><lifetimetype="perRequest"/></type>
Note the "perRequest" setting. This type (defined also in the unity.config file) sets a UnityHttpContextPerRequestLifetimeManager as the lifetime manager for the MileageStatsDbContext instance. As the name implies, this lifetime manager always provides the same instance of MileageStatsDbContext to any class for the current request. For example, each repository created to handle a request made by the client will receive the same context upon construction.

Thanks,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Viewing all articles
Browse latest Browse all 93

Trending Articles