You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
abp/templates/service/host/IdentityServerHost/IdentityServerHostModule.cs

89 lines
2.8 KiB

using System;
using System.Linq;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.AspNetCore.Modularity;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Autofac;
using Volo.Abp.Data;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.SqlServer;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.EntityFrameworkCore;
using Volo.Abp.Modularity;
namespace IdentityServerHost
{
[DependsOn(
typeof(AbpAutofacModule),
typeof(AbpAspNetCoreMvcModule),
typeof(AbpIdentityServerEntityFrameworkCoreModule),
typeof(AbpEntityFrameworkCoreSqlServerModule)
)]
public class IdentityServerHostModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.BuildConfiguration();
context.Services.Configure<DbConnectionOptions>(options =>
{
options.ConnectionStrings.Default = configuration.GetConnectionString("Default");
});
context.Services.Configure<AbpDbContextOptions>(options =>
{
options.UseSqlServer();
});
context.Services.Configure<IISOptions>(iis =>
{
iis.AuthenticationDisplayName = "Windows";
iis.AutomaticAuthentication = false;
});
//TODO: Configure distributed cache?
//context.Services.AddDistributedSqlServerCache(options =>
//{
// options.ConnectionString = configuration.GetConnectionString("Default");
// options.SchemaName = "dbo";
// options.TableName = "TestCache";
//});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var app = context.GetApplicationBuilder();
app.UseVirtualFiles();
app.UseAuthentication();
app.UseIdentityServer();
app.UseMvcWithDefaultRoute();
SeedData(context);
}
private void SeedData(ApplicationInitializationContext context)
{
using (var scope = context.ServiceProvider.CreateScope())
{
var clientRepository = scope.ServiceProvider.GetRequiredService<IRepository<Client, Guid>>();
if (clientRepository.Any())
{
return;
}
var client = new Client(Guid.NewGuid(), "test-client");
clientRepository.Insert(client);
}
}
}
}