This project is read-only.

StartupInstallers

If you had implemented a select method at your repository, like GetDataById above, you need to write the query that will be mapped to your return type. In this case I need to write a query that returns a Data object.

[Export(typeof(IStartupInstaller))]
public class StartupInstaller : IStartupInstaller
    {
        public InstallationStatus Status { get; set; }
      
        public InstallerPriority Priority
        {
                  get { return InstallerPriority.Medium; }
        }

        public void Install()
        {
            QueryStore.AddCommand<IDataRepository>("GetDataById", "select * from TBL_Data where id = @0");
            QueryStore.ConnectionString = "Data Source=.;User Id=sa;Password=Aa123456;Initial Catalog=Test";
        }
    }

As seen above, StartupInstallers implements IStartupInstaller interface. This forces installer classes to implement Status property and void Install() method.

StartupInstaller is the place that needed to be executed at your applications first run. It is same as a Boot Loader. In this example QueryStore.AddCommand method adds a query to the GetDataById method of the IDataRepository. Query parameter is also given as @0 which represents the first parameter of the GetDataById method. This also can be written as the parameter name like this one;

 QueryStore.AddCommand<IDataRepository>("GetDataById", "select * from TBL_Data where id = @id");

There is also a strongly typed option for writing basic queries;

            QueryStore.Expression<IDataRepository, Data>("GetDataById").
                Select()
                .Where<int, string>(
                         (m, id) => m.IsActive == true && m.Id == id)
                .OrderBy(m => m.Id)
                .AddToStore();

But this option does not yet supports complex queries with join.

StartupInstallers can be installed when the application is executed with the method below,

CrowCore.Start();

If the startup installer is on the AppDomain then it will be loaded with no configuration else we should spesify the assembly which our installer is at. However we also need to determine the installers priority among all the installers. We can do that with the DependsOn attribute. If the installer depends on another installer then it should be marked with DependsOn attribute and spesify the depending type. Since Crow needs to initialize its own components, every installer must be depends on the CrowStartupInstaller. However we made an exception for the CrowFX's installers.

        [Export(typeof(IStartupInstaller))]
        [DependsOn(typeof(DemoStartupInstallerBaseBase))]
        public class DemoStartupInstallerBase : IStartupInstaller
        {
            public InstallationStatus Status { get; set; }

            public void Install()
            {
                      /* .... */
            }
        }

In this example above, Installer is depends on the another installer. And these dependencies are resolved at runtime while application first load.

(this operations might slowdown first application startup. This situation is going to be solved in first stable release.)

Last edited Aug 10, 2012 at 1:33 PM by msusur, version 1

Comments

No comments yet.