Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

IStartupTask

Describes startup task purposes and configurations.

Method

void Run(IAppBuilder app, HttpConfiguration config);

Executes the startup task.

  • app – The builder used to configure an application running on OWIN.
  • config – The object used to configure Web API applications.

Remarks

Startup tasks are used to configure components of the Commerce (SaaS) application, such as IdentityServer (authentication and authorization), Web API (Storefront API), and the internal WIS (runs locally in Debug mode). These tasks run in a configured order during the application boot process, right after the IOC container is initialized and configured.

The order in which the tasks run is configured using the [BootStrapperOrder] attribute. Startup tasks MUST be decorated at the class level using this attribute. The BootStrapperOrder attribute constructor takes an integer as an argument, which indicates when the task should be run relative to the other startup tasks. The lowest order that is allowed is zero (0). No other attribute of the startup task is used for ordering. When multiple startup tasks specify the same order, the order is indeterminate. As a best practice to ensure proper ordering, you should not specify the same order for multiple startup tasks.

Example: Configure the embedded IdentityServer with a startup task

The code sample is an abbreviated version of the actual startup task.

[BootStrapperOrder(25)]
public class ConfigureIdentityServer : IStartupTask
{
	public void Run(IAppBuilder app, HttpConfiguration config)
    {
		app.Map("/identity", identityApp =>
		{
			identityApp.UseIdentityServer(new IdentityServerOptions
			{
				SiteName = "Optimizely Commerce - Identity Server",
				CspOptions = new CspOptions { Enabled = false },
				SigningCertificate = Certificate.Get(),
				Factory = Factory.Configure(ConnectionStringProvider.Current.ConnectionStringName),
				AuthenticationOptions = new AuthenticationOptions
				{
					IdentityProviders = ConfigureIdentityProviders
				},
				IssuerUri = SecurityOptions.IssuerUri,
				RequireSsl = SecurityOptions.RequireSsl
			});
		});
	}

	// ...
}