Service load order

From SocialStack
Revision as of 19:58, 29 September 2022 by Luke (talk | contribs) (Created page with "Most of the time it doesn't matter which order services load in - it will be automatically established based on dependencies. Sometimes though it can be useful to give a guara...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Most of the time it doesn't matter which order services load in - it will be automatically established based on dependencies. Sometimes though it can be useful to give a guarantee that a service loads before other services. That can be done by setting the LoadPriority attribute on a service, like so:

using Api.Startup;
namespace Api.Things;


[LoadPriority(5)]
public partial class ThingService : AutoService<Thing>
{

}

If a load priority is not specified the default value is 10 just like with event listeners. The lower the number you give, the sooner it runs. LoadPriority(1) runs before LoadPriority(10).