Skip to content

Applications

Andrew Bullock edited this page Jun 2, 2018 · 6 revisions

Applications are the container within a MustardBlack project which hold all the details of how the website should work.

For typical usages, you probably want just a single Application:

public class ExampleApplication : ApplicationBase
{
	public ExampleApplication(IContainer container) : base(container)
	{
	}

	public override Type DefaultErrorHandler { get; }
	public override bool CanServe(IRequest request)
	{
		throw new NotImplementedException();
	}

	protected override void Configure()
	{
		throw new NotImplementedException();
	}
}

There are three things to implement...

Type DefaultErrorHandler

This defines the type for the Handler in your application which handles errors. It should implement IDefaultErrorHandler. This is used by MustardBlack in catastrophe scenarios where some misconfiguration or other exception has occurred and all that can be done to recover the experience for the user is to handle the request as an Internal Server Error.

bool CanServe(IRequest request)

This is a very crude routing mechanism for when your project contains multiple Applications. If you only have a single application, then this wants to return true. If you have multiple applications, you need to write logic for both.

Two Applications in the same project may have CanServe implemented like this, for example:

public override bool CanServe(IRequest request)
{
	return request.Url.Port == 80 || request.Url.Port == 443;
}

...

public override bool CanServe(IRequest request)
{
	return request.Url.Port == 8080;
}

The IApplicationRouter within MustardBlack emits useful Debug logs as it iterates over all the Applications' CanServe() methods. See these if you're having application routing trouble.

void Configure()

This is where all the configuration for your Application needs to happen. Here you will define the Areas in your application, any Authentication Mechanisms and the Pipeline Operators to run for each request.

TODO

Clone this wiki locally