views:

178

answers:

1

I'm trying to enable SqlCacheDependency through my StructureMap IoC, I'm using LinqToSql I have the code done to take care of the Linq Caching but not quite sure how to go about setting up the SqlCacheDependency as it requires putting this in a global.asa file

void Application_Start(object sender, EventArgs e) 
{
    string connectionString = WebConfigurationManager.
        ConnectionStrings["Catalog"].ConnectionString;
    SqlDependency.Start(connectionString);
}

However my repository doesn't use a global.asa as its just a library (.dll) not a web application.

Any ideas how to do this? Maybe put whats in the application_start method into the constructor of my repository?

+1  A: 

Moving that code into a constructor should be fine.

I often place a static Initialize() method on anything that requires explicit initialization. If my code is sanitary for external use I also throw my own UninitializedException if a method is invoked before the Initialize method is used.

My Global.asax tends to contain several blah.Initialize() invocations as a result.

cfeduke