This project is no longer maintained and has been made obsolete by improvements to the ASP.NET Core platform. Consider building your warm up routines in your main entry point, i.e., Program.cs
. For example:
class Program {
static void WarmUp(ApplicationDbContext context) {
context.Users.FirstOrDefault();
}
static void Main(string[] args) {
var host = CreateHostBuilder(args).Build();
WarmUp(
host.Services
.GetRequiredService<ApplicationDbContext>()
);
host.Run();
}
}
Amp.NET provides warm up routines to ASP.NET Core applications.
Released under the MIT License. See the LICENSE file for further details.
In the Package Manager Console execute
Install-Package Amp
Or update *.csproj
to include a dependency on
<ItemGroup>
<PackageReference Include="Amp" Version="0.1.0-*" />
</ItemGroup>
You can configure your application in order to specify Amp's behavior.
- Path - (
"/warmup"
) The path which invokes the asynchronous initialization - Parallelism - (
WarmUpParallelism.Parallel
) Execution flow for each individualIWarmUp
.
public void ConfigureServices(IServiceCollection services) =>
services.AddWarmUp(builder => {
builder.Path = "/my-custom-path";
builder.Parallelism = WarmUpParallelism.Sequential;
});
You can warm up your application in one of two ways: asynchronous or synchronous.
Use asynchronous warm up when you want to initialize the system separately from application boot up.
public void Configure(IApplicationBuilder app, IHostingEnvironment env) =>
app.UseWarmUp().UseMvc();
Use synchronous warm up when you need to initialize the system before the application begins to take requests.
public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
app.WarmUpAsync().GetAwaiter().GetResult();
app.UseMvc();
}
Sample integration with Entity Framework Core:
class Startup {
...
public void ConfigureServices(IServiceCollection services) =>
services.AddWarmUp().AddScoped<IWarmUp, ApplicationDbContextWarmUp>();
public void Configure(IApplicationBuilder app, IHostingEnvironment env) =>
app.UseWarmUp().UseMvc();
}
class ApplicationDbContextWarmUp : IWarmUp {
readonly ApplicationDbContext _context;
public ApplicationDbContextWarmUp(ApplicationDbContext context) => _context = context;
public Task InvokeAsync() => _context.Users.AnyAsync();
}
For additional usage see Tests.