This project is read-only.

Bootstrappers and Modules

In CrowFX you can design your modules and let them loaded by the Bootstrappers. Modules are the small tiny objects that are run when the applications are started. And they have designed for creating modular applications.

Module Concept

If you are designing applications in CrowFX you need to start implementing your own Module. In previous versions of CrowFX these objects were called StartupInstallers. This term is now turned into a word that developers are more familiar. And also there were improvements were made.

In modules you may define your application's needs and dependencies. You can bind your Business Classes with their interfaces, register your queries, and anything that should run when the application is started. See the example below;

    [Export(typeof(IModule))]
    public class SampleModule : IModule
    {
        public void Install(IInjectionContainer container, IQueryStore queryStore)
        {
            string provider = "System.Data.SqlClient";
            string connectionString = "";
            queryStore.ConnectionString = new ConnectionStringInformation(connectionString, provider);

            queryStore.Expression<IDataRepository, Data>("LoadDataById")
                         .Select()
                         .Where<int>((data, idParam) => data.Id == idParam)
                         .OrderBy((d) => d.Id)
                         .AddToStore(); 

            container.Bind<IDataBusiness, DataBusinessClass>();
        }
    }

As seen above, Modules are implements the IModule interface. This forces installer classes to implement void Install(IInjectionContainer container, IQueryStore queryStore) method. And since CrowFX bootloaders uses the MEF in order to find and execute module objects, you also need to add an Exports attribute to the module.

Bootstrappers

Bootstrapper is the class that triggers the Module loader. Uses MEF Assembly catalog for loading assemblies in the executable folder. You can also customize this process by inheriting the Bootstrapper class.

 public class CustomBootstrapper : Bootstrapper
    {
        protected override void LoadModules(IEnumerable<Assembly> assemblies)
        {
            base.LoadModules(assemblies);
        }
    }

A bootstrapper must be called on the application start;

 Bootstrapper bootstrapper = new CustomBootstrapper();
 bootstrapper.Start();

Solving Dependency Problem at Modules

In some cases a module might be depend to another module. These cases can be solved by DependsOn attribute. Suppose you have a CompanyCoreModule, that is used in every project in your applications. And since your company has a few project, every new project must be depend on this CompanyCoreModule and they need to be run after this module. You can manage this case like this;


    [Export(typeof(IModule))]
    [DependsOn(typeof(CompanyCoreModule))]
    public class SampleModule : IModule
    {
               // Install implementation
    }

this attribute tells the bootstrapper that SampleModule must be installed after CompanyCoreModule successfully installed.


Last edited Aug 17, 2012 at 9:50 PM by msusur, version 1

Comments

No comments yet.