Skip to content

Custom Simplify.Web bootstrapper

Alexanderius edited this page Jun 6, 2024 · 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 generator as a decorator to existing generator

First, you create your class which you want to use

public class MyPageGenerator(IPageGenerator baseGenerator) : IPageGenerator
{
	public string Generate(IDataCollector dataCollector)
	{
		var result = baseGenerator.Generate(dataCollector);

		// Your custom code

		return result;
	}
}

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

public class MyBootstrapper : BaseBootstrapper
{
	public override void RegisterPageGenerator()
	{
		BootstrapperFactory.ContainerProvider.Register<PageGenerator>();

		BootstrapperFactory.ContainerProvider.Register<IPageGenerator>(r => new MyPageGenerator(r.Resolve<PageGenerator>));

	}
}
  • MyBootstrapper class will be loaded by framework automatically when framework starts.

Another way of overriding an internal type registrations

You can override an internal type by using RegisterSimplifyWeb override parameter:

.RegisterSimplifyWeb(registrationsOverride: x =>
{
    x.OverridePageGenerator(r =>
    {
        r.Register<PageGenerator>();
        r.Register<IPageGenerator>(r => new MyPageGenerator(r.Resolve<PageGenerator>));
    });
})

<< Previous page Next page >>

Clone this wiki locally