ASP.NET Boilerplate provides an infrastructure to configure it and modules on startup.

Configuring ASP.NET Boilerplate

Configuring ASP.NET Boilerplate is made on PreInitialize event of your module. Example configuration:

public class SimpleTaskSystemModule : AbpModule
{
    public override void PreInitialize()
    {
        //Add languages for your application
        Configuration.Localization.Languages.Add(new LanguageInfo("en", "English", "famfamfam-flag-england", true));
        Configuration.Localization.Languages.Add(new LanguageInfo("tr", "Türkçe", "famfamfam-flag-tr"));

        //Add a localization source
        Configuration.Localization.Sources.Add(
            new XmlLocalizationSource(
                "SimpleTaskSystem",
                HttpContext.Current.Server.MapPath("~/Localization/SimpleTaskSystem")
                )
            );

        //Configure navigation/menu
        Configuration.Navigation.Providers.Add<SimpleTaskSystemNavigationProvider>();
    }

    public override void Initialize()
    {
        IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
    }
}

ASP.NET Boilerplate is designed modularity in mind. Different modules can configure ASP.NET Boilerplate. For example, different modules can add navigation provider to add their own menu items to the main menu. See localization and navigation documents for details.

Configuring Modules

Beside framework's own startup configuration, a module can extend IAbpModuleConfigurations interface to provide configuration points for the module. Example:

...
using Abp.Web.Configuration;
...
public override void PreInitialize() 
{
    Configuration.Modules.AbpWeb().SendAllExceptionsToClients = true;
}
...

In this example, we configured AbpWeb module to send all exceptions to clients.

Not every module should define this type of configuration. It's generally needed when a module will be re-usable in different applications and needs to be configured on startup.

Creating configuration for a module

Assume that we have a module named MyModule and it has some configuration properties. First, we create a class for these cofigurable properties:

public class MyModuleConfig
{
    public bool SampleConfig1 { get; set; }

    public string SampleConfig2 { get; set; }
}

Then we register this class to DI on PreInitialize event of MyModule (Thus, it will be injectable):

IocManager.Register<MyModuleConfig>();

Finally, we create an extension method to IModuleConfigurations to get a reference to the MyConfig:

public static class MyModuleConfigurationExtensions
{
    public static MyModuleConfig MyModule(this IModuleConfigurations moduleConfigurations)
    {
        return moduleConfigurations.AbpConfiguration
            .GetOrCreate("MyModuleConfig",
                () => moduleConfigurations.AbpConfiguration.IocManager.Resolve<MyModuleConfig>()
            );
    }
}

Now, other modules can configure this module on startup (on PreInitialize event of the module which need to configure MyModule):

Configuration.Modules.MyModule().SampleConfig1 = false;
Configuration.Modules.MyModule().SampleConfig2 = "test";

At some point, MyModule needs to this configuration. You can inject MyModuleConfig and use configured values. Example:

public class MyService : ITransientDependency
{
    private readonly MyModuleConfig _configuration;

    public MyService(MyModuleConfig configuration)
    {
        _configuration = configuration;
    }

    public void DoIt()
    {
        if (_configuration.SampleConfig2 == "test")
        {
            //...
        }
    }
}

Thus, modules can create central configuration points in ASP.NET Boilerplate system.