Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Custom Simplify.Web bootstrapper

Alexanderius edited this page Jun 30, 2019 · 2 revisions

Custom Simplify.Web bootstrapper

Each Simplify.Web framework class is replaceable, you can create your implementation of any class and use it instead of, to do that, you should create a class in your web-site assembly derived from BaseBootstrapper and then use provided methods to register your implementation.

Basic types registration

Some Simplify.Web classes by default registered using general register method of IOC container without custom creation. For that classes your can just simply set a type.

For example, if you want to use your custom page processor

First, you create your class which you want to use

public class MyPageProcessor : IPageProcessor
{
    private readonly PageProcessor _pp;

    public MyPageProcessor(IPageBuilder pageBuilder, IResponseWriter responseWriter, IRedirector redirector)
    {
        _pp = new PageProcessor(pageBuilder, responseWriter, redirector);
    }

    public Task ProcessPage(IDIContainerProvider containerProvider, IOwinContext context)
    {
        // some custom code

        return _pp.ProcessPage(containerProvider, context);
    }
}

Then, create your custom bootstrapper and set page processor type in constructor

public class MyBootstrapper : BaseBootstrapper
{
    public MyBootstrapper()
    {
        // Setting type of your page processor
        SetPageProcessorType<MyPageProcessor>();
    }
}
  • MyBootstrapper class will be loaded by framework automatically when framework starts.

Types with complex constructor registration

Some Simplify.Web types created only by register delegate of IOC container, for example, Environment:

public virtual void RegisterEnvironment()
{
    DIContainer.Current.Register<IEnvironment>(
        p => new Environment(AppDomain.CurrentDomain.BaseDirectory, p.Resolve<ISimplifyWebSettings>()));
}

For such king of classes you should override respective Register method (you can do the same for basic Simplify.Web types also).

Example

Your custom Environment:

public class MyEnvironment : IEnvironment
{
    public MyEnvironment()
    {
    }

    ...
}

Registration override

public class MyBootstrapper : BaseBootstrapper
{
    public override void RegisterEnvironment()
    {
        DIContainer.Current.Register<IEnvironment, MyEnvironment>();
    }
}

<< Previous page Next page >>

Clone this wiki locally