33
loading...
This website collects cookies to deliver better user experience
public
class
WebHost
{
public
virtual
async
Task StartAsync(CancellationToken cancellationToken =
default
)
{
// Fire IHostedService.Start
await
_hostedServiceExecutor.StartAsync(cancellationToken).ConfigureAwait(
false
);
// More setup
await
Server.StartAsync(hostingApp, cancellationToken).ConfigureAwait(
false
);
// Fire IApplicationLifetime.Started
_applicationLifetime?.NotifyStarted();
// Remaining setup
}
}
public
async
Task<List> GetBlogsAsync()
{
using
(
var
context =
new
BloggingContext())
{
return
await
context.Blogs.ToListAsync();
}
}
public
static
async
Task AddBlogAsync(
string
url)
{
using
(
var
context =
new
BloggingContext())
{
var
blogContent =
new
BlogContent { Url = url };
context.Blogs.Add(blogContent);
await
context.SaveChangesAsync();
}
}
public
void
ConfigureServices(IServiceCollection services)
{
services.AddResponseCaching();
services.AddRazorPages();
}
public
class
Startup
{
public
void
ConfigureServices(IServiceCollection services)
{
services.AddResponseCompression();
}
public
void
Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseResponseCompression();
}
}
public
void
ConfigureServices(IServiceCollection services)
{
services.AddResponseCompression(options =>
{
options.Providers.Add<BrotliCompressionProvider>();
options.Providers.Add<GzipCompressionProvider>();
options.Providers.Add<CustomCompressionProvider>();
options.MimeTypes =
ResponseCompressionDefaults.MimeTypes.Concat(
new
[] {
"image/svg+xml"
});
});
}