Skip to content
Dmitry Savchenko edited this page Jul 15, 2016 · 13 revisions

Let us begin with a short description of the Framework. Incoding Framework comprises four packages: Incoding framework – back-end of a project, Incoding Meta Language – front-end of a project, Incoding Meta Language Contrib - extenstion of the Incoding Meta Language, and Incoding tests helpers – unit-tests for back-end. These packages are installed independently of each other, that makes it possible to integrate framework by parts into the project: You can connect only front-end or back-end (tests are tightly coupled with the back-end, so, they could be more considered as a complement).

Projects developed with Incoding Framework use CQRS as a server architecture. Incoding Meta Language is used as a basic tool for building front-end. All in all, Incoding Framework covers the entire application development cycle.

Typical solution, that was developed using Incoding Framework, comprises 3 projects:

  1. Domain (class library) - is responsible for business logic and database operations.
  2. UI (ASP.NET MVC project) - front-end based on ASP.NET MVC.
  3. UnitTests (class library)- unit-tests for Domain.

Domain

After installation of Incoding framework package through Nuget, along with the necessary dll, Bootstrapper.cs file will be added in the project. The file is mainly responsible for the initialization of an application: logging initialization, IoC registration, installation of Ajax-requests settings, etc. By default, StructureMap is installed as loC framework, but there is a provider for Ninject, and it is also possible to write your own implementations.

Bootstrapper.cs
``` namespace Example.Domain { #region << Using >>
using System;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Web.Mvc;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentValidation;
using FluentValidation.Mvc;
using Incoding.Block.IoC;
using Incoding.Block.Logging;
using Incoding.CQRS;
using Incoding.Data;
using Incoding.EventBroker;
using Incoding.Extensions;
using Incoding.MvcContrib;
using NHibernate.Tool.hbm2ddl;
using StructureMap.Graph;

#endregion

public static class Bootstrapper
{
    public static void Start()
    {
        LoggingFactory.Instance.Initialize(logging =>
        {
            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log");
            logging.WithPolicy(policy =>
                                policy.For(LogType.Debug)
                                    .Use(FileLogger.WithAtOnceReplace(path,
                                                                        () => "Debug_{0}.txt".F(DateTime.Now.ToString("yyyyMMdd")))));
        });

        IoCFactory.Instance.Initialize(init =>init.WithProvider(new StructureMapIoCProvider(registry =>
        {
            registry.For<IDispatcher>().Use<DefaultDispatcher>();
            registry.For<IEventBroker>().Use<DefaultEventBroker>();
            registry.For<ITemplateFactory>().Singleton().Use<TemplateHandlebarsFactory>();

            var configure = Fluently
                    .Configure()
                    .Database(MsSqlConfiguration.MsSql2008.ConnectionString(ConfigurationManager.ConnectionStrings["Main"].ConnectionString))
                    .Mappings(configuration => configuration.FluentMappings.AddFromAssembly(typeof(Bootstrapper).Assembly))
                    .ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true))
                    .CurrentSessionContext<NhibernateSessionContext>();
            registry.For<INhibernateSessionFactory>().Singleton().Use(() => new NhibernateSessionFactory(configure));
            registry.For<IUnitOfWorkFactory>().Use<NhibernateUnitOfWorkFactory>();
            registry.For<IRepository>().Use<NhibernateRepository>();

            registry.Scan(r =>
                        {
                            r.TheCallingAssembly();
                            r.WithDefaultConventions();

                            r.ConnectImplementationsToTypesClosing(typeof(AbstractValidator<>));
                            r.ConnectImplementationsToTypesClosing(typeof(IEventSubscriber<>));
                            r.AddAllTypesOf<ISetUp>();
                        });
        })));

        ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(new IncValidatorFactory()));
        FluentValidationModelValidatorProvider.Configure();

        foreach (var setUp in IoCFactory.Instance.ResolveAll<ISetUp>().OrderBy(r => r.GetOrder()))
            setUp.Execute();

        var ajaxDef = JqueryAjaxOptions.Default;
        ajaxDef.Cache = false; // disabled cache as default
    }
}

}

<p>Further on, commands and queries are added to <em>Domain</em>, that perform database operations or any action, related with business application logic.</p>
<h3>UI</h3>
<p>During the installation of <a title="Nuget: Incoding Meta Language" href="https://www.nuget.org/packages/Incoding.MetaLanguage/">Incoding Meta Language</a> package, it adds the necessary dll to the package, as well as <em>IncodingStart.cs</em> and <em>DispatcherController.cs</em> (part of a <a title="Habrahabr: Model View Dispatcher (cqrs over mvc)" href="http://habrahabr.ru/post/221585/">MVD</a>) files that required for <em>Domain</em>.</p>
<h6>IncodingStart.cs</h6>

public static class IncodingStart { public static void PreStart() { Bootstrapper.Start(); new DispatcherController(); // init routes } }

<h6>DispatcherController.cs</h6>

public class DispatcherController : DispatcherControllerBase { #region Constructors

public DispatcherController()
        : base(typeof(Bootstrapper).Assembly) { }

#endregion

}

<p>After the installation, the client logic is added to <em>UI</em> using IML.</p>
<h3>UnitTests</h3>
<p>During the installation of <a title="Nuget: Incoding tests helpers" href="https://www.nuget.org/packages/Incoding.MSpecContrib/">Incoding tests helpers</a> package, the project is added by the <em>MSpecAssemblyContext.cs</em> file, in which connection is customize to the test database.</p>
<h6>MSpecAssemblyContext.cs</h6>

public class MSpecAssemblyContext : IAssemblyContext { #region IAssemblyContext Members

public void OnAssemblyStart()
{
    //Configuration data base
    var configure = Fluently
            .Configure()
            .Database(MsSqlConfiguration.MsSql2008
                                        .ConnectionString(ConfigurationManager.ConnectionStrings["Example_Test"].ConnectionString)
                                        .ShowSql())
            .Mappings(configuration =&gt; configuration.FluentMappings.AddFromAssembly(typeof(Bootstrapper).Assembly));
    PleasureForData.StartNhibernate(configure, true);
}

public void OnAssemblyComplete() { }

#endregion

}

<br/>
<p>
<ul>
<li><a href="/IncodingSoftware/get-started/wiki/2.-Installation">Next</a></li>
</ul>
</p>
Clone this wiki locally