Fill the Static Query Library

(This is an optional step.) DatabaseService is the abstract service from which all of the implementation classes derive. This class contains a static query library, which can be used by applications to fill queries once per application start, instead of filling them each time an IDatabaseService instance is created. To fill these, use code similar to the following:

    DatabaseService.FillStaticQueryLibrary(typeof(FirstQueryProvider),
        typeof(SecondQueryProvider));
If you have IQueryFragmentProviders, you can include them in the list in any order.

    DatabaseService.FillStaticQueryLibrary(typeof(FirstFragmentProvider),
        typeof(SecondFragmentProvider), typeof(FirstQueryProvider),
        typeof(SecondQueryProvider));
A good place for this is in the Application_Start() method found in Global.asax.cs. An example...

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            
            DatabaseService.FillStaticQueryLibrary(typeof(ExampleQueryProvider));
            // ^-- This is the line we added
        }
TIP: This can be a step that is easy to forget when you create a new query library or fragment provider; it also introduces a dependency on files that should probably be maintained external to the web application (the ExampleQueryProvider.cs file). If you don't have your business logic separated from your presentation logic, this is not a problem; however, creating a public static method in your business logic layer that handles this, then calling that from Application_Start(), is a much cleaner implementation.

Last edited May 6, 2012 at 5:06 AM by danielsummers, version 4

Comments

No comments yet.