mirror of https://github.com/abpframework/abp.git
42 changed files with 1152 additions and 21174 deletions
@ -0,0 +1,22 @@ |
|||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
|
||||
|
namespace MyCompanyName.MyProjectName.Server.Data; |
||||
|
|
||||
|
[ConnectionStringName("Default")] |
||||
|
public class MyProjectNameDbContext : AbpMongoDbContext |
||||
|
{ |
||||
|
/* Add mongo collections here. Example: |
||||
|
* public IMongoCollection<Question> Questions => Collection<Question>(); |
||||
|
*/ |
||||
|
|
||||
|
protected override void CreateModel(IMongoModelBuilder modelBuilder) |
||||
|
{ |
||||
|
base.CreateModel(modelBuilder); |
||||
|
|
||||
|
//builder.Entity<YourEntity>(b =>
|
||||
|
//{
|
||||
|
// //...
|
||||
|
//});
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,88 @@ |
|||||
|
using Microsoft.Extensions.Logging.Abstractions; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Identity; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.TenantManagement; |
||||
|
|
||||
|
namespace MyCompanyName.MyProjectName.Server.Data; |
||||
|
|
||||
|
public class MyProjectNameDbMigrationService : ITransientDependency |
||||
|
{ |
||||
|
public ILogger<MyProjectNameDbMigrationService> Logger { get; set; } |
||||
|
|
||||
|
private readonly IDataSeeder _dataSeeder; |
||||
|
private readonly MyProjectNameMongoDbSchemaMigrator _dbSchemaMigrator; |
||||
|
private readonly ITenantRepository _tenantRepository; |
||||
|
private readonly ICurrentTenant _currentTenant; |
||||
|
|
||||
|
public MyProjectNameDbMigrationService( |
||||
|
IDataSeeder dataSeeder, |
||||
|
MyProjectNameMongoDbSchemaMigrator dbSchemaMigrator, |
||||
|
ITenantRepository tenantRepository, |
||||
|
ICurrentTenant currentTenant) |
||||
|
{ |
||||
|
_dataSeeder = dataSeeder; |
||||
|
_dbSchemaMigrator = dbSchemaMigrator; |
||||
|
_tenantRepository = tenantRepository; |
||||
|
_currentTenant = currentTenant; |
||||
|
|
||||
|
Logger = NullLogger<MyProjectNameDbMigrationService>.Instance; |
||||
|
} |
||||
|
|
||||
|
public async Task MigrateAsync() |
||||
|
{ |
||||
|
Logger.LogInformation("Started database migrations..."); |
||||
|
|
||||
|
await MigrateDatabaseSchemaAsync(); |
||||
|
await SeedDataAsync(); |
||||
|
|
||||
|
Logger.LogInformation($"Successfully completed host database migrations."); |
||||
|
|
||||
|
var tenants = await _tenantRepository.GetListAsync(includeDetails: true); |
||||
|
|
||||
|
var migratedDatabaseSchemas = new HashSet<string>(); |
||||
|
foreach (var tenant in tenants) |
||||
|
{ |
||||
|
using (_currentTenant.Change(tenant.Id)) |
||||
|
{ |
||||
|
if (tenant.ConnectionStrings.Any()) |
||||
|
{ |
||||
|
var tenantConnectionStrings = tenant.ConnectionStrings |
||||
|
.Select(x => x.Value) |
||||
|
.ToList(); |
||||
|
|
||||
|
if (!migratedDatabaseSchemas.IsSupersetOf(tenantConnectionStrings)) |
||||
|
{ |
||||
|
await MigrateDatabaseSchemaAsync(tenant); |
||||
|
|
||||
|
migratedDatabaseSchemas.AddIfNotContains(tenantConnectionStrings); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
await SeedDataAsync(tenant); |
||||
|
} |
||||
|
|
||||
|
Logger.LogInformation($"Successfully completed {tenant.Name} tenant database migrations."); |
||||
|
} |
||||
|
|
||||
|
Logger.LogInformation("Successfully completed all database migrations."); |
||||
|
Logger.LogInformation("You can safely end this process..."); |
||||
|
} |
||||
|
|
||||
|
private async Task MigrateDatabaseSchemaAsync(Tenant? tenant = null) |
||||
|
{ |
||||
|
Logger.LogInformation($"Migrating schema for {(tenant == null ? "host" : tenant.Name + " tenant")} database..."); |
||||
|
await _dbSchemaMigrator.MigrateAsync(); |
||||
|
} |
||||
|
|
||||
|
private async Task SeedDataAsync(Tenant? tenant = null) |
||||
|
{ |
||||
|
Logger.LogInformation($"Executing {(tenant == null ? "host" : tenant.Name + " tenant")} database seed..."); |
||||
|
|
||||
|
await _dataSeeder.SeedAsync(new DataSeedContext(tenant?.Id) |
||||
|
.WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, IdentityDataSeedContributor.AdminEmailDefaultValue) |
||||
|
.WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, IdentityDataSeedContributor.AdminPasswordDefaultValue) |
||||
|
); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,39 @@ |
|||||
|
using MongoDB.Driver; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
|
||||
|
namespace MyCompanyName.MyProjectName.Server.Data; |
||||
|
|
||||
|
public class MyProjectNameMongoDbSchemaMigrator : ITransientDependency |
||||
|
{ |
||||
|
private readonly IServiceProvider _serviceProvider; |
||||
|
|
||||
|
public MyProjectNameMongoDbSchemaMigrator(IServiceProvider serviceProvider) |
||||
|
{ |
||||
|
_serviceProvider = serviceProvider; |
||||
|
} |
||||
|
|
||||
|
public async Task MigrateAsync() |
||||
|
{ |
||||
|
var dbContexts = _serviceProvider.GetServices<IAbpMongoDbContext>(); |
||||
|
var connectionStringResolver = _serviceProvider.GetRequiredService<IConnectionStringResolver>(); |
||||
|
|
||||
|
foreach (var dbContext in dbContexts) |
||||
|
{ |
||||
|
var connectionString = |
||||
|
await connectionStringResolver.ResolveAsync( |
||||
|
ConnectionStringNameAttribute.GetConnStringName(dbContext.GetType())); |
||||
|
var mongoUrl = new MongoUrl(connectionString); |
||||
|
var databaseName = mongoUrl.DatabaseName; |
||||
|
var client = new MongoClient(mongoUrl); |
||||
|
|
||||
|
if (databaseName.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
databaseName = ConnectionStringNameAttribute.GetConnStringName(dbContext.GetType()); |
||||
|
} |
||||
|
|
||||
|
(dbContext as AbpMongoDbContext)?.InitializeCollections(client.GetDatabase(databaseName)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,308 @@ |
|||||
|
using JetBrains.Annotations; |
||||
|
using Microsoft.Extensions.Localization; |
||||
|
using OpenIddict.Abstractions; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Authorization.Permissions; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.OpenIddict.Applications; |
||||
|
using Volo.Abp.PermissionManagement; |
||||
|
using Volo.Abp.Uow; |
||||
|
|
||||
|
namespace MyCompanyName.MyProjectName.Server.Data; |
||||
|
|
||||
|
/* Creates initial data that is needed to property run the application |
||||
|
* and make client-to-server communication possible. |
||||
|
*/ |
||||
|
public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDependency |
||||
|
{ |
||||
|
private readonly IConfiguration _configuration; |
||||
|
private readonly IOpenIddictApplicationManager _applicationManager; |
||||
|
private readonly IOpenIddictScopeManager _scopeManager; |
||||
|
private readonly IPermissionDataSeeder _permissionDataSeeder; |
||||
|
private readonly IStringLocalizer<OpenIddictResponse> L; |
||||
|
|
||||
|
public OpenIddictDataSeedContributor( |
||||
|
IConfiguration configuration, |
||||
|
IOpenIddictApplicationManager applicationManager, |
||||
|
IOpenIddictScopeManager scopeManager, |
||||
|
IPermissionDataSeeder permissionDataSeeder, |
||||
|
IStringLocalizer<OpenIddictResponse> l) |
||||
|
{ |
||||
|
_configuration = configuration; |
||||
|
_applicationManager = applicationManager; |
||||
|
_scopeManager = scopeManager; |
||||
|
_permissionDataSeeder = permissionDataSeeder; |
||||
|
L = l; |
||||
|
} |
||||
|
|
||||
|
[UnitOfWork] |
||||
|
public virtual async Task SeedAsync(DataSeedContext context) |
||||
|
{ |
||||
|
await CreateScopesAsync(); |
||||
|
await CreateApplicationsAsync(); |
||||
|
} |
||||
|
|
||||
|
private async Task CreateScopesAsync() |
||||
|
{ |
||||
|
if (await _scopeManager.FindByNameAsync("MyProjectName") == null) |
||||
|
{ |
||||
|
await _scopeManager.CreateAsync(new OpenIddictScopeDescriptor |
||||
|
{ |
||||
|
Name = "MyProjectName", |
||||
|
DisplayName = "MyProjectName API", |
||||
|
Resources = |
||||
|
{ |
||||
|
"MyProjectName" |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private async Task CreateApplicationsAsync() |
||||
|
{ |
||||
|
var commonScopes = new List<string> |
||||
|
{ |
||||
|
OpenIddictConstants.Permissions.Scopes.Address, |
||||
|
OpenIddictConstants.Permissions.Scopes.Email, |
||||
|
OpenIddictConstants.Permissions.Scopes.Phone, |
||||
|
OpenIddictConstants.Permissions.Scopes.Profile, |
||||
|
OpenIddictConstants.Permissions.Scopes.Roles, |
||||
|
"MyProjectName" |
||||
|
}; |
||||
|
|
||||
|
var configurationSection = _configuration.GetSection("OpenIddict:Applications"); |
||||
|
|
||||
|
//Blazor Client
|
||||
|
var blazorClientId = configurationSection["MyProjectName_Blazor:ClientId"]; |
||||
|
if (!blazorClientId.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
var blazorRootUrl = configurationSection["MyProjectName_Blazor:RootUrl"]?.TrimEnd('/'); |
||||
|
await CreateApplicationAsync( |
||||
|
name: blazorClientId!, |
||||
|
type: OpenIddictConstants.ClientTypes.Public, |
||||
|
consentType: OpenIddictConstants.ConsentTypes.Implicit, |
||||
|
displayName: "Blazor Application", |
||||
|
secret: null, |
||||
|
grantTypes: new List<string> |
||||
|
{ |
||||
|
OpenIddictConstants.GrantTypes.AuthorizationCode |
||||
|
}, |
||||
|
scopes: commonScopes, |
||||
|
redirectUri: $"{blazorRootUrl}/authentication/login-callback", |
||||
|
clientUri: blazorRootUrl, |
||||
|
postLogoutRedirectUri: $"{blazorRootUrl}/authentication/logout-callback" |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
// Swagger Client
|
||||
|
var swaggerClientId = configurationSection["MyProjectName_Swagger:ClientId"]; |
||||
|
if (!swaggerClientId.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
var swaggerRootUrl = configurationSection["MyProjectName_Swagger:RootUrl"]?.TrimEnd('/'); |
||||
|
|
||||
|
await CreateApplicationAsync( |
||||
|
name: swaggerClientId!, |
||||
|
type: OpenIddictConstants.ClientTypes.Public, |
||||
|
consentType: OpenIddictConstants.ConsentTypes.Implicit, |
||||
|
displayName: "Swagger Application", |
||||
|
secret: null, |
||||
|
grantTypes: new List<string> |
||||
|
{ |
||||
|
OpenIddictConstants.GrantTypes.AuthorizationCode, |
||||
|
}, |
||||
|
scopes: commonScopes, |
||||
|
redirectUri: $"{swaggerRootUrl}/swagger/oauth2-redirect.html" |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private async Task CreateApplicationAsync( |
||||
|
[NotNull] string name, |
||||
|
[NotNull] string type, |
||||
|
[NotNull] string consentType, |
||||
|
string displayName, |
||||
|
string? secret, |
||||
|
List<string> grantTypes, |
||||
|
List<string> scopes, |
||||
|
string? clientUri = null, |
||||
|
string? redirectUri = null, |
||||
|
string? postLogoutRedirectUri = null, |
||||
|
List<string>? permissions = null) |
||||
|
{ |
||||
|
if (!string.IsNullOrEmpty(secret) && string.Equals(type, OpenIddictConstants.ClientTypes.Public, StringComparison.OrdinalIgnoreCase)) |
||||
|
{ |
||||
|
throw new BusinessException(L["NoClientSecretCanBeSetForPublicApplications"]); |
||||
|
} |
||||
|
|
||||
|
if (string.IsNullOrEmpty(secret) && string.Equals(type, OpenIddictConstants.ClientTypes.Confidential, StringComparison.OrdinalIgnoreCase)) |
||||
|
{ |
||||
|
throw new BusinessException(L["TheClientSecretIsRequiredForConfidentialApplications"]); |
||||
|
} |
||||
|
|
||||
|
if (!string.IsNullOrEmpty(name) && await _applicationManager.FindByClientIdAsync(name) != null) |
||||
|
{ |
||||
|
return; |
||||
|
//throw new BusinessException(L["TheClientIdentifierIsAlreadyTakenByAnotherApplication"]);
|
||||
|
} |
||||
|
|
||||
|
var client = await _applicationManager.FindByClientIdAsync(name); |
||||
|
if (client == null) |
||||
|
{ |
||||
|
var application = new AbpApplicationDescriptor |
||||
|
{ |
||||
|
ClientId = name, |
||||
|
Type = type, |
||||
|
ClientSecret = secret, |
||||
|
ConsentType = consentType, |
||||
|
DisplayName = displayName, |
||||
|
ClientUri = clientUri |
||||
|
}; |
||||
|
|
||||
|
Check.NotNullOrEmpty(grantTypes, nameof(grantTypes)); |
||||
|
Check.NotNullOrEmpty(scopes, nameof(scopes)); |
||||
|
|
||||
|
if (new [] { OpenIddictConstants.GrantTypes.AuthorizationCode, OpenIddictConstants.GrantTypes.Implicit }.All(grantTypes.Contains)) |
||||
|
{ |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.ResponseTypes.CodeIdToken); |
||||
|
|
||||
|
if (string.Equals(type, OpenIddictConstants.ClientTypes.Public, StringComparison.OrdinalIgnoreCase)) |
||||
|
{ |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.ResponseTypes.CodeIdTokenToken); |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.ResponseTypes.CodeToken); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (!redirectUri.IsNullOrWhiteSpace() || !postLogoutRedirectUri.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.Endpoints.Logout); |
||||
|
} |
||||
|
|
||||
|
foreach (var grantType in grantTypes) |
||||
|
{ |
||||
|
if (grantType == OpenIddictConstants.GrantTypes.AuthorizationCode) |
||||
|
{ |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode); |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.ResponseTypes.Code); |
||||
|
} |
||||
|
|
||||
|
if (grantType == OpenIddictConstants.GrantTypes.AuthorizationCode || grantType == OpenIddictConstants.GrantTypes.Implicit) |
||||
|
{ |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.Endpoints.Authorization); |
||||
|
} |
||||
|
|
||||
|
if (grantType == OpenIddictConstants.GrantTypes.AuthorizationCode || |
||||
|
grantType == OpenIddictConstants.GrantTypes.ClientCredentials || |
||||
|
grantType == OpenIddictConstants.GrantTypes.Password || |
||||
|
grantType == OpenIddictConstants.GrantTypes.RefreshToken || |
||||
|
grantType == OpenIddictConstants.GrantTypes.DeviceCode) |
||||
|
{ |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.Endpoints.Token); |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.Endpoints.Revocation); |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.Endpoints.Introspection); |
||||
|
} |
||||
|
|
||||
|
if (grantType == OpenIddictConstants.GrantTypes.ClientCredentials) |
||||
|
{ |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.GrantTypes.ClientCredentials); |
||||
|
} |
||||
|
|
||||
|
if (grantType == OpenIddictConstants.GrantTypes.Implicit) |
||||
|
{ |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.GrantTypes.Implicit); |
||||
|
} |
||||
|
|
||||
|
if (grantType == OpenIddictConstants.GrantTypes.Password) |
||||
|
{ |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.GrantTypes.Password); |
||||
|
} |
||||
|
|
||||
|
if (grantType == OpenIddictConstants.GrantTypes.RefreshToken) |
||||
|
{ |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.GrantTypes.RefreshToken); |
||||
|
} |
||||
|
|
||||
|
if (grantType == OpenIddictConstants.GrantTypes.DeviceCode) |
||||
|
{ |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.GrantTypes.DeviceCode); |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.Endpoints.Device); |
||||
|
} |
||||
|
|
||||
|
if (grantType == OpenIddictConstants.GrantTypes.Implicit) |
||||
|
{ |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.ResponseTypes.IdToken); |
||||
|
if (string.Equals(type, OpenIddictConstants.ClientTypes.Public, StringComparison.OrdinalIgnoreCase)) |
||||
|
{ |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.ResponseTypes.IdTokenToken); |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.ResponseTypes.Token); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
var buildInScopes = new [] |
||||
|
{ |
||||
|
OpenIddictConstants.Permissions.Scopes.Address, |
||||
|
OpenIddictConstants.Permissions.Scopes.Email, |
||||
|
OpenIddictConstants.Permissions.Scopes.Phone, |
||||
|
OpenIddictConstants.Permissions.Scopes.Profile, |
||||
|
OpenIddictConstants.Permissions.Scopes.Roles |
||||
|
}; |
||||
|
|
||||
|
foreach (var scope in scopes) |
||||
|
{ |
||||
|
if (buildInScopes.Contains(scope)) |
||||
|
{ |
||||
|
application.Permissions.Add(scope); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
application.Permissions.Add(OpenIddictConstants.Permissions.Prefixes.Scope + scope); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (redirectUri != null) |
||||
|
{ |
||||
|
if (!redirectUri.IsNullOrEmpty()) |
||||
|
{ |
||||
|
if (!Uri.TryCreate(redirectUri, UriKind.Absolute, out var uri) || !uri.IsWellFormedOriginalString()) |
||||
|
{ |
||||
|
throw new BusinessException(L["InvalidRedirectUri", redirectUri]); |
||||
|
} |
||||
|
|
||||
|
if (application.RedirectUris.All(x => x != uri)) |
||||
|
{ |
||||
|
application.RedirectUris.Add(uri); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (postLogoutRedirectUri != null) |
||||
|
{ |
||||
|
if (!postLogoutRedirectUri.IsNullOrEmpty()) |
||||
|
{ |
||||
|
if (!Uri.TryCreate(postLogoutRedirectUri, UriKind.Absolute, out var uri) || !uri.IsWellFormedOriginalString()) |
||||
|
{ |
||||
|
throw new BusinessException(L["InvalidPostLogoutRedirectUri", postLogoutRedirectUri]); |
||||
|
} |
||||
|
|
||||
|
if (application.PostLogoutRedirectUris.All(x => x != uri)) |
||||
|
{ |
||||
|
application.PostLogoutRedirectUris.Add(uri); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (permissions != null) |
||||
|
{ |
||||
|
await _permissionDataSeeder.SeedAsync( |
||||
|
ClientPermissionValueProvider.ProviderName, |
||||
|
name, |
||||
|
permissions, |
||||
|
null |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
await _applicationManager.CreateAsync(application); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,99 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk.Web"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>net7.0</TargetFramework> |
||||
|
<Nullable>enable</Nullable> |
||||
|
<ImplicitUsings>enable</ImplicitUsings> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="7.0.0" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" /> |
||||
|
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc\Volo.Abp.AspNetCore.Mvc.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.Swashbuckle\Volo.Abp.Swashbuckle.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.AspNetCore.Authentication.JwtBearer\Volo.Abp.AspNetCore.Authentication.JwtBearer.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.AspNetCore.Serilog\Volo.Abp.AspNetCore.Serilog.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\account\src\Volo.Abp.Account.Application\Volo.Abp.Account.Application.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\account\src\Volo.Abp.Account.HttpApi\Volo.Abp.Account.HttpApi.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\account\src\Volo.Abp.Account.Web.OpenIddict\Volo.Abp.Account.Web.OpenIddict.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\identity\src\Volo.Abp.PermissionManagement.Domain.Identity\Volo.Abp.PermissionManagement.Domain.Identity.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\identity\src\Volo.Abp.Identity.Application\Volo.Abp.Identity.Application.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\identity\src\Volo.Abp.Identity.HttpApi\Volo.Abp.Identity.HttpApi.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\identity\src\Volo.Abp.Identity.MongoDB\Volo.Abp.Identity.MongoDB.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\openiddict\src\Volo.Abp.OpenIddict.MongoDB\Volo.Abp.OpenIddict.MongoDB.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\openiddict\src\Volo.Abp.PermissionManagement.Domain.OpenIddict\Volo.Abp.PermissionManagement.Domain.OpenIddict.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\permission-management\src\Volo.Abp.PermissionManagement.Application\Volo.Abp.PermissionManagement.Application.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\permission-management\src\Volo.Abp.PermissionManagement.MongoDB\Volo.Abp.PermissionManagement.MongoDB.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\permission-management\src\Volo.Abp.PermissionManagement.HttpApi\Volo.Abp.PermissionManagement.HttpApi.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\tenant-management\src\Volo.Abp.TenantManagement.Application\Volo.Abp.TenantManagement.Application.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\tenant-management\src\Volo.Abp.TenantManagement.MongoDB\Volo.Abp.TenantManagement.MongoDB.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\tenant-management\src\Volo.Abp.TenantManagement.HttpApi\Volo.Abp.TenantManagement.HttpApi.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\feature-management\src\Volo.Abp.FeatureManagement.Application\Volo.Abp.FeatureManagement.Application.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\feature-management\src\Volo.Abp.FeatureManagement.MongoDB\Volo.Abp.FeatureManagement.MongoDB.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\feature-management\src\Volo.Abp.FeatureManagement.HttpApi\Volo.Abp.FeatureManagement.HttpApi.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\setting-management\src\Volo.Abp.SettingManagement.Application\Volo.Abp.SettingManagement.Application.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\setting-management\src\Volo.Abp.SettingManagement.MongoDB\Volo.Abp.SettingManagement.MongoDB.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\setting-management\src\Volo.Abp.SettingManagement.HttpApi\Volo.Abp.SettingManagement.HttpApi.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\..\..\..\modules\audit-logging\src\Volo.Abp.AuditLogging.MongoDB\Volo.Abp.AuditLogging.MongoDB.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<!-- <TEMPLATE-REMOVE> --> |
||||
|
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy\Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\..\framework\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" /> |
||||
|
<!-- </TEMPLATE-REMOVE> --> |
||||
|
<PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite" Version="2.0.0-*" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="7.0.0" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\Client\MyCompanyName.MyProjectName.Blazor.WebAssembly.Client.csproj" /> |
||||
|
<ProjectReference Include="..\Shared\MyCompanyName.MyProjectName.Blazor.WebAssembly.Shared.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<Compile Remove="Logs\**" /> |
||||
|
<Content Remove="Logs\**" /> |
||||
|
<EmbeddedResource Remove="Logs\**" /> |
||||
|
<None Remove="Logs\**" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<Content Remove="$(UserProfile)\.nuget\packages\*\*\contentFiles\any\*\*.abppkg*.json" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,318 @@ |
|||||
|
using Microsoft.AspNetCore.Cors; |
||||
|
using Microsoft.AspNetCore.DataProtection; |
||||
|
using Microsoft.AspNetCore.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
||||
|
using Microsoft.OpenApi.Models; |
||||
|
using MyCompanyName.MyProjectName.Server.Data; |
||||
|
using MyCompanyName.MyProjectName.Shared.Localization; |
||||
|
using MyCompanyName.MyProjectName.Shared; |
||||
|
using MyCompanyName.MyProjectName.Shared.MultiTenancy; |
||||
|
using OpenIddict.Validation.AspNetCore; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Account; |
||||
|
using Volo.Abp.Account.Web; |
||||
|
using Volo.Abp.AspNetCore.MultiTenancy; |
||||
|
using Volo.Abp.AspNetCore.Mvc; |
||||
|
using Volo.Abp.AspNetCore.Mvc.Localization; |
||||
|
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
||||
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite; |
||||
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite.Bundling; |
||||
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; |
||||
|
using Volo.Abp.AspNetCore.Serilog; |
||||
|
using Volo.Abp.AuditLogging.MongoDB; |
||||
|
using Volo.Abp.Autofac; |
||||
|
using Volo.Abp.AutoMapper; |
||||
|
using Volo.Abp.Emailing; |
||||
|
using Volo.Abp.FeatureManagement; |
||||
|
using Volo.Abp.FeatureManagement.MongoDB; |
||||
|
using Volo.Abp.Identity; |
||||
|
using Volo.Abp.Identity.MongoDB; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.OpenIddict.MongoDB; |
||||
|
using Volo.Abp.PermissionManagement; |
||||
|
using Volo.Abp.PermissionManagement.MongoDB; |
||||
|
using Volo.Abp.PermissionManagement.HttpApi; |
||||
|
using Volo.Abp.PermissionManagement.Identity; |
||||
|
using Volo.Abp.PermissionManagement.OpenIddict; |
||||
|
using Volo.Abp.SettingManagement; |
||||
|
using Volo.Abp.SettingManagement.MongoDB; |
||||
|
using Volo.Abp.Swashbuckle; |
||||
|
using Volo.Abp.TenantManagement; |
||||
|
using Volo.Abp.TenantManagement.MongoDB; |
||||
|
using Volo.Abp.UI.Navigation.Urls; |
||||
|
using Volo.Abp.Uow; |
||||
|
using Volo.Abp.VirtualFileSystem; |
||||
|
|
||||
|
namespace MyCompanyName.MyProjectName.Server; |
||||
|
|
||||
|
[DependsOn( |
||||
|
|
||||
|
typeof(MyProjectNameSharedModule), |
||||
|
|
||||
|
// ABP Framework packages
|
||||
|
typeof(AbpAspNetCoreMvcModule), |
||||
|
typeof(AbpAspNetCoreMultiTenancyModule), |
||||
|
typeof(AbpAutofacModule), |
||||
|
typeof(AbpAutoMapperModule), |
||||
|
typeof(AbpAspNetCoreMvcUiLeptonXLiteThemeModule), |
||||
|
typeof(AbpSwashbuckleModule), |
||||
|
typeof(AbpAspNetCoreSerilogModule), |
||||
|
|
||||
|
// Account module packages
|
||||
|
typeof(AbpAccountApplicationModule), |
||||
|
typeof(AbpAccountHttpApiModule), |
||||
|
typeof(AbpAccountWebOpenIddictModule), |
||||
|
|
||||
|
// Identity module packages
|
||||
|
typeof(AbpPermissionManagementDomainIdentityModule), |
||||
|
typeof(AbpPermissionManagementDomainOpenIddictModule), |
||||
|
typeof(AbpIdentityApplicationModule), |
||||
|
typeof(AbpIdentityHttpApiModule), |
||||
|
typeof(AbpIdentityMongoDbModule), |
||||
|
typeof(AbpOpenIddictMongoDbModule), |
||||
|
|
||||
|
// Audit logging module packages
|
||||
|
typeof(AbpAuditLoggingMongoDbModule), |
||||
|
|
||||
|
// Permission Management module packages
|
||||
|
typeof(AbpPermissionManagementApplicationModule), |
||||
|
typeof(AbpPermissionManagementHttpApiModule), |
||||
|
typeof(AbpPermissionManagementMongoDbModule), |
||||
|
|
||||
|
// Tenant Management module packages
|
||||
|
typeof(AbpTenantManagementApplicationModule), |
||||
|
typeof(AbpTenantManagementHttpApiModule), |
||||
|
typeof(AbpTenantManagementMongoDbModule), |
||||
|
|
||||
|
// Feature Management module packages
|
||||
|
typeof(AbpFeatureManagementApplicationModule), |
||||
|
typeof(AbpFeatureManagementMongoDbModule), |
||||
|
typeof(AbpFeatureManagementHttpApiModule), |
||||
|
|
||||
|
// Setting Management module packages
|
||||
|
typeof(AbpSettingManagementApplicationModule), |
||||
|
typeof(AbpSettingManagementMongoDbModule), |
||||
|
typeof(AbpSettingManagementHttpApiModule) |
||||
|
)] |
||||
|
public class MyProjectNameServerModule : AbpModule |
||||
|
{ |
||||
|
public override void PreConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
context.Services.PreConfigure<AbpMvcDataAnnotationsLocalizationOptions>(options => |
||||
|
{ |
||||
|
options.AddAssemblyResource( |
||||
|
typeof(MyProjectNameResource) |
||||
|
); |
||||
|
}); |
||||
|
|
||||
|
PreConfigure<OpenIddictBuilder>(builder => |
||||
|
{ |
||||
|
builder.AddValidation(options => |
||||
|
{ |
||||
|
options.AddAudiences("MyProjectName"); |
||||
|
options.UseLocalServer(); |
||||
|
options.UseAspNetCore(); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
var hostingEnvironment = context.Services.GetHostingEnvironment(); |
||||
|
var configuration = context.Services.GetConfiguration(); |
||||
|
|
||||
|
if (hostingEnvironment.IsDevelopment()) |
||||
|
{ |
||||
|
context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>()); |
||||
|
} |
||||
|
|
||||
|
ConfigureAuthentication(context); |
||||
|
ConfigureBundles(); |
||||
|
ConfigureMultiTenancy(); |
||||
|
ConfigureUrls(configuration); |
||||
|
ConfigureAutoMapper(context); |
||||
|
ConfigureSwagger(context.Services, configuration); |
||||
|
ConfigureAutoApiControllers(); |
||||
|
ConfigureVirtualFiles(hostingEnvironment); |
||||
|
ConfigureCors(context, configuration); |
||||
|
ConfigureDataProtection(context); |
||||
|
ConfigureMongoDB(context); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureAuthentication(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureBundles() |
||||
|
{ |
||||
|
Configure<AbpBundlingOptions>(options => |
||||
|
{ |
||||
|
options.StyleBundles.Configure( |
||||
|
LeptonXLiteThemeBundles.Styles.Global, |
||||
|
bundle => { bundle.AddFiles("/global-styles.css"); } |
||||
|
); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureMultiTenancy() |
||||
|
{ |
||||
|
Configure<AbpMultiTenancyOptions>(options => |
||||
|
{ |
||||
|
options.IsEnabled = MultiTenancyConsts.IsEnabled; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureUrls(IConfiguration configuration) |
||||
|
{ |
||||
|
Configure<AppUrlOptions>(options => |
||||
|
{ |
||||
|
options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"]; |
||||
|
options.RedirectAllowedUrls.AddRange(configuration["App:RedirectAllowedUrls"]?.Split(',') ?? Array.Empty<string>()); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureVirtualFiles(IWebHostEnvironment hostingEnvironment) |
||||
|
{ |
||||
|
Configure<AbpVirtualFileSystemOptions>(options => |
||||
|
{ |
||||
|
options.FileSets.AddEmbedded<MyProjectNameServerModule>(); |
||||
|
if (hostingEnvironment.IsDevelopment()) |
||||
|
{ |
||||
|
/* Using physical files in development, so we don't need to recompile on changes */ |
||||
|
options.FileSets.ReplaceEmbeddedByPhysical<MyProjectNameServerModule>(hostingEnvironment.ContentRootPath); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureAutoApiControllers() |
||||
|
{ |
||||
|
Configure<AbpAspNetCoreMvcOptions>(options => |
||||
|
{ |
||||
|
options.ConventionalControllers.Create(typeof(MyProjectNameServerModule).Assembly); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureSwagger(IServiceCollection services, IConfiguration configuration) |
||||
|
{ |
||||
|
services.AddAbpSwaggerGenWithOAuth( |
||||
|
configuration["AuthServer:Authority"], |
||||
|
new Dictionary<string, string> |
||||
|
{ |
||||
|
{"MyProjectName", "MyProjectName API"} |
||||
|
}, |
||||
|
options => |
||||
|
{ |
||||
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "MyProjectName API", Version = "v1" }); |
||||
|
options.DocInclusionPredicate((docName, description) => true); |
||||
|
options.CustomSchemaIds(type => type.FullName); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureAutoMapper(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
context.Services.AddAutoMapperObjectMapper<MyProjectNameServerModule>(); |
||||
|
Configure<AbpAutoMapperOptions>(options => |
||||
|
{ |
||||
|
/* Uncomment `validate: true` if you want to enable the Configuration Validation feature. |
||||
|
* See AutoMapper's documentation to learn what it is: |
||||
|
* https://docs.automapper.org/en/stable/Configuration-validation.html
|
||||
|
*/ |
||||
|
options.AddMaps<MyProjectNameServerModule>(/* validate: true */); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration) |
||||
|
{ |
||||
|
context.Services.AddCors(options => |
||||
|
{ |
||||
|
options.AddDefaultPolicy(builder => |
||||
|
{ |
||||
|
builder |
||||
|
.WithOrigins( |
||||
|
configuration["App:CorsOrigins"]? |
||||
|
.Split(",", StringSplitOptions.RemoveEmptyEntries) |
||||
|
.Select(o => o.RemovePostFix("/")) |
||||
|
.ToArray() ?? Array.Empty<string>() |
||||
|
) |
||||
|
.WithAbpExposedHeaders() |
||||
|
.SetIsOriginAllowedToAllowWildcardSubdomains() |
||||
|
.AllowAnyHeader() |
||||
|
.AllowAnyMethod() |
||||
|
.AllowCredentials(); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureDataProtection(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
context.Services.AddDataProtection().SetApplicationName("MyProjectName"); |
||||
|
} |
||||
|
|
||||
|
private void ConfigureMongoDB(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
context.Services.AddMongoDbContext<MyProjectNameDbContext>(options => |
||||
|
{ |
||||
|
options.AddDefaultRepositories(); |
||||
|
}); |
||||
|
|
||||
|
Configure<AbpUnitOfWorkDefaultOptions>(options => |
||||
|
{ |
||||
|
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
||||
|
{ |
||||
|
var app = context.GetApplicationBuilder(); |
||||
|
var env = context.GetEnvironment(); |
||||
|
|
||||
|
if (env.IsDevelopment()) |
||||
|
{ |
||||
|
app.UseDeveloperExceptionPage(); |
||||
|
} |
||||
|
|
||||
|
app.UseAbpRequestLocalization(); |
||||
|
|
||||
|
if (!env.IsDevelopment()) |
||||
|
{ |
||||
|
app.UseErrorPage(); |
||||
|
} |
||||
|
|
||||
|
app.UseCorrelationId(); |
||||
|
app.UseBlazorFrameworkFiles(); |
||||
|
app.UseStaticFiles(); |
||||
|
app.UseRouting(); |
||||
|
app.UseCors(); |
||||
|
app.UseAuthentication(); |
||||
|
app.UseAbpOpenIddictValidation(); |
||||
|
|
||||
|
if (MultiTenancyConsts.IsEnabled) |
||||
|
{ |
||||
|
app.UseMultiTenancy(); |
||||
|
} |
||||
|
|
||||
|
app.UseUnitOfWork(); |
||||
|
app.UseAuthorization(); |
||||
|
|
||||
|
app.UseSwagger(); |
||||
|
app.UseAbpSwaggerUI(options => |
||||
|
{ |
||||
|
options.SwaggerEndpoint("/swagger/v1/swagger.json", "MyProjectName API"); |
||||
|
|
||||
|
var configuration = context.GetConfiguration(); |
||||
|
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); |
||||
|
options.OAuthScopes("MyProjectName"); |
||||
|
}); |
||||
|
|
||||
|
app.UseAuditing(); |
||||
|
app.UseAbpSerilogEnrichers(); |
||||
|
app.UseConfiguredEndpoints(); |
||||
|
|
||||
|
if (app is WebApplication webApp) |
||||
|
{ |
||||
|
webApp.MapFallbackToFile("index.html"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
using AutoMapper; |
||||
|
|
||||
|
namespace MyCompanyName.MyProjectName.Server.ObjectMapping; |
||||
|
|
||||
|
public class MyProjectNameAutoMapperProfile : Profile |
||||
|
{ |
||||
|
public MyProjectNameAutoMapperProfile() |
||||
|
{ |
||||
|
/* Create your AutoMapper object mappings here */ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,81 @@ |
|||||
|
using MyCompanyName.MyProjectName.Server; |
||||
|
using MyCompanyName.MyProjectName.Server.Data; |
||||
|
using Serilog; |
||||
|
using Serilog.Events; |
||||
|
using Volo.Abp.Data; |
||||
|
|
||||
|
public class Program |
||||
|
{ |
||||
|
public async static Task<int> Main(string[] args) |
||||
|
{ |
||||
|
//<TEMPLATE-REMOVE IF-NOT='dbms:PostgreSQL'>
|
||||
|
// https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic
|
||||
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); |
||||
|
|
||||
|
//</TEMPLATE-REMOVE>
|
||||
|
var loggerConfiguration = new LoggerConfiguration() |
||||
|
#if DEBUG
|
||||
|
.MinimumLevel.Debug() |
||||
|
#else
|
||||
|
.MinimumLevel.Information() |
||||
|
#endif
|
||||
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) |
||||
|
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) |
||||
|
.Enrich.FromLogContext() |
||||
|
.WriteTo.Async(c => c.File("Logs/logs.txt")) |
||||
|
.WriteTo.Async(c => c.Console()); |
||||
|
|
||||
|
if (IsMigrateDatabase(args)) |
||||
|
{ |
||||
|
loggerConfiguration.MinimumLevel.Override("Volo.Abp", LogEventLevel.Warning); |
||||
|
loggerConfiguration.MinimumLevel.Override("Microsoft", LogEventLevel.Warning); |
||||
|
} |
||||
|
|
||||
|
Log.Logger = loggerConfiguration.CreateLogger(); |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
|
||||
|
var builder = WebApplication.CreateBuilder(args); |
||||
|
builder.Host.AddAppSettingsSecretsJson() |
||||
|
.UseAutofac() |
||||
|
.UseSerilog(); |
||||
|
await builder.AddApplicationAsync<MyProjectNameServerModule>(); |
||||
|
if (IsMigrateDatabase(args)) |
||||
|
{ |
||||
|
builder.Services.AddDataMigrationEnvironment(); |
||||
|
} |
||||
|
var app = builder.Build(); |
||||
|
await app.InitializeApplicationAsync(); |
||||
|
|
||||
|
if (IsMigrateDatabase(args)) |
||||
|
{ |
||||
|
await app.Services.GetRequiredService<MyProjectNameDbMigrationService>().MigrateAsync(); |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
Log.Information("Starting MyCompanyName.MyProjectName."); |
||||
|
await app.RunAsync(); |
||||
|
return 0; |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
if (ex is HostAbortedException) |
||||
|
{ |
||||
|
throw; |
||||
|
} |
||||
|
|
||||
|
Log.Fatal(ex, "MyCompanyName.MyProjectName terminated unexpectedly!"); |
||||
|
return 1; |
||||
|
} |
||||
|
finally |
||||
|
{ |
||||
|
Log.CloseAndFlush(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static bool IsMigrateDatabase(string[] args) |
||||
|
{ |
||||
|
return args.Any(x => x.Contains("--migrate-database", StringComparison.OrdinalIgnoreCase)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
{ |
||||
|
"iisSettings": { |
||||
|
"windowsAuthentication": false, |
||||
|
"anonymousAuthentication": true, |
||||
|
"iisExpress": { |
||||
|
"applicationUrl": "https://localhost:44300", |
||||
|
"sslPort": 44300 |
||||
|
} |
||||
|
}, |
||||
|
"profiles": { |
||||
|
"https": { |
||||
|
"commandName": "Project", |
||||
|
"dotnetRunMessages": true, |
||||
|
"launchBrowser": true, |
||||
|
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", |
||||
|
"applicationUrl": "https://localhost:44300", |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
} |
||||
|
}, |
||||
|
"IIS Express": { |
||||
|
"commandName": "IISExpress", |
||||
|
"launchBrowser": true, |
||||
|
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", |
||||
|
"environmentVariables": { |
||||
|
"ASPNETCORE_ENVIRONMENT": "Development" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,31 @@ |
|||||
|
{ |
||||
|
"App": { |
||||
|
"SelfUrl": "https://localhost:44300", |
||||
|
"CorsOrigins": "https://*.MyProjectName.com,http://localhost:44300", |
||||
|
"RedirectAllowedUrls": "http://localhost:44300" |
||||
|
}, |
||||
|
"ConnectionStrings": { |
||||
|
"Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=MyProjectName;Trusted_Connection=True;TrustServerCertificate=True" |
||||
|
}, |
||||
|
"AuthServer": { |
||||
|
"Authority": "https://localhost:44300", |
||||
|
"RequireHttpsMetadata": "false", |
||||
|
"SwaggerClientId": "MyProjectName_Swagger", |
||||
|
"SwaggerClientSecret": "1q2w3e*" |
||||
|
}, |
||||
|
"StringEncryption": { |
||||
|
"DefaultPassPhrase": "gsKnGZ041HLL4IM8" |
||||
|
}, |
||||
|
"OpenIddict": { |
||||
|
"Applications": { |
||||
|
"MyProjectName_Blazor": { |
||||
|
"ClientId": "MyProjectName_Blazor", |
||||
|
"RootUrl": "https://localhost:44300" |
||||
|
}, |
||||
|
"MyProjectName_Swagger": { |
||||
|
"ClientId": "MyProjectName_Swagger", |
||||
|
"RootUrl": "https://localhost:44300" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
{ |
||||
|
"version": "1.0.0", |
||||
|
"name": "my-app", |
||||
|
"private": true, |
||||
|
"dependencies": { |
||||
|
"@abp/aspnetcore.mvc.ui.theme.leptonxlite": "~2.0.0-rc.1" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<configuration> |
||||
|
<location path="." inheritInChildApplications="false"> |
||||
|
<system.webServer> |
||||
|
<handlers> |
||||
|
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /> |
||||
|
</handlers> |
||||
|
<aspNetCore processPath="dotnet" arguments=".\MyCompanyName.MyProjectName.Server.dll" stdoutLogEnabled="false" stdoutLogFile=".\Logs\stdout" hostingModel="inprocess" /> |
||||
|
</system.webServer> |
||||
|
</location> |
||||
|
<system.webServer> |
||||
|
<httpProtocol> |
||||
|
<customHeaders> |
||||
|
<remove name="x-powered-by" /> |
||||
|
</customHeaders> |
||||
|
</httpProtocol> |
||||
|
</system.webServer> |
||||
|
</configuration> |
||||
@ -0,0 +1,8 @@ |
|||||
|
/* Your Global Styles */ |
||||
|
|
||||
|
/* <TEMPLATE-REMOVE IF-NOT='LEPTONX'> */ |
||||
|
:root .lpx-brand-logo { |
||||
|
--lpx-logo: url('/images/logo/leptonx/logo-light.png'); |
||||
|
--lpx-logo-icon: url('/images/logo/leptonx/logo-light-thumbnail.png'); |
||||
|
} |
||||
|
/* </TEMPLATE-REMOVE> */ |
||||
File diff suppressed because it is too large
Loading…
Reference in new issue