Add MongoDB project

pull/14938/head
liangshiwei 3 years ago
parent 44ebcd0ac8
commit 9172d3b428

@ -1,6 +1,6 @@
using MyCompanyName.MyProjectName.Blazor.Menus;
using MyCompanyName.MyProjectName.Blazor.WebAssembly.Shared.Localization;
using MyCompanyName.MyProjectName.Blazor.WebAssembly.Shared.MultiTenancy;
using MyCompanyName.MyProjectName.Shared.Localization;
using MyCompanyName.MyProjectName.Shared.MultiTenancy;
using Volo.Abp.Account.Localization;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Identity.Blazor;
@ -8,7 +8,7 @@ using Volo.Abp.SettingManagement.Blazor.Menus;
using Volo.Abp.TenantManagement.Blazor.Navigation;
using Volo.Abp.UI.Navigation;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Client.Menus;
namespace MyCompanyName.MyProjectName.Client.Menus;
public class MyProjectNameMenuContributor : IMenuContributor
{
@ -45,9 +45,9 @@ public class MyProjectNameMenuContributor : IMenuContributor
order: 0
)
);
var administration = context.Menu.GetAdministration();
if (MultiTenancyConsts.IsEnabled)
{
administration.SetSubItemOrder(TenantManagementMenuNames.GroupName, 1);
@ -56,7 +56,7 @@ public class MyProjectNameMenuContributor : IMenuContributor
{
administration.TryRemoveMenuItem(TenantManagementMenuNames.GroupName);
}
administration.SetSubItemOrder(IdentityMenuNames.GroupName, 2);
administration.SetSubItemOrder(SettingManagementMenus.GroupName, 3);

@ -1,6 +1,6 @@
using AutoMapper;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Client;
namespace MyCompanyName.MyProjectName.Client;
public class MyProjectNameBlazorAutoMapperProfile : Profile
{

@ -1,8 +1,8 @@
using Blazorise.Bootstrap5;
using Blazorise.Icons.FontAwesome;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using MyCompanyName.MyProjectName.Blazor.WebAssembly.Client.Menus;
using MyCompanyName.MyProjectName.Blazor.WebAssembly.Shared;
using MyCompanyName.MyProjectName.Client.Menus;
using MyCompanyName.MyProjectName.Shared;
using OpenIddict.Abstractions;
using Volo.Abp.Account;
using Volo.Abp.AspNetCore.Components.Web.LeptonXLiteTheme.Themes.LeptonXLite;
@ -22,33 +22,33 @@ using Volo.Abp.TenantManagement;
using Volo.Abp.TenantManagement.Blazor.WebAssembly;
using Volo.Abp.UI.Navigation;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Client;
namespace MyCompanyName.MyProjectName.Client;
[DependsOn(
typeof(MyProjectNameSharedModule),
// ABP Framework packages
typeof(AbpAutofacWebAssemblyModule),
typeof(AbpAspNetCoreComponentsWebAssemblyLeptonXLiteThemeModule),
// Account module packages
typeof(AbpAccountHttpApiClientModule),
// Identity module packages
typeof(AbpIdentityHttpApiClientModule),
typeof(AbpIdentityBlazorWebAssemblyModule),
typeof(AbpOpenIddictDomainSharedModule),
// Permission Management module packages
typeof(AbpPermissionManagementHttpApiClientModule),
// Tenant Management module packages
typeof(AbpTenantManagementHttpApiClientModule),
typeof(AbpTenantManagementBlazorWebAssemblyModule),
// Feature Management module packages
typeof(AbpFeatureManagementHttpApiClientModule),
// Setting Management module packages
typeof(AbpSettingManagementHttpApiClientModule),
typeof(AbpSettingManagementBlazorWebAssemblyModule)
@ -56,7 +56,7 @@ namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Client;
public class MyProjectNameBlazorModule : AbpModule
{
public const string RemoteServiceName = "Default";
public override void ConfigureServices(ServiceConfigurationContext context)
{
var environment = context.Services.GetSingletonInstance<IWebAssemblyHostEnvironment>();
@ -94,7 +94,7 @@ public class MyProjectNameBlazorModule : AbpModule
.AddBootstrap5Providers()
.AddFontAwesomeIcons();
}
private void ConfigureHttpClientProxies(ServiceConfigurationContext context)
{
context.Services.AddHttpClientProxies(
@ -139,4 +139,4 @@ public class MyProjectNameBlazorModule : AbpModule
options.AddMaps<MyProjectNameBlazorModule>();
});
}
}
}

@ -1,7 +1,7 @@
using Volo.Abp.DependencyInjection;
using Volo.Abp.Ui.Branding;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Client;
namespace MyCompanyName.MyProjectName.Client;
[Dependency(ReplaceServices = true)]
public class MyProjectNameBrandingProvider : DefaultBrandingProvider

@ -1,6 +1,6 @@
using Volo.Abp.Bundling;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Client;
namespace MyCompanyName.MyProjectName.Client;
/* Add your global styles/scripts here.
* See https://docs.abp.io/en/abp/latest/UI/Blazor/Global-Scripts-Styles to learn how to use it

@ -1,7 +1,7 @@
using MyCompanyName.MyProjectName.Blazor.WebAssembly.Shared.Localization;
using MyCompanyName.MyProjectName.Shared.Localization;
using Volo.Abp.AspNetCore.Components;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Client;
namespace MyCompanyName.MyProjectName.Client;
public abstract class MyProjectNameComponentBase : AbpComponentBase
{

@ -1,4 +1,4 @@
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Client.Pages;
namespace MyCompanyName.MyProjectName.Client.Pages;
public partial class Index
{

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Client;
namespace MyCompanyName.MyProjectName.Client;
public class Program
{

@ -7,7 +7,7 @@
@using Microsoft.AspNetCore.Components.WebAssembly.Http
@using Microsoft.JSInterop
@using Volo.Abp.AspNetCore.Components.Web
@using MyCompanyName.MyProjectName.Blazor.WebAssembly.Client
@using MyCompanyName.MyProjectName.Client
@using Blazorise
@using Blazorise.DataGrid
@using Volo.Abp.BlazoriseUI

@ -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> */

@ -8,7 +8,7 @@ using Volo.Abp.PermissionManagement.EntityFrameworkCore;
using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.Data;
namespace MyCompanyName.MyProjectName.Server.Data;
public class MyProjectNameDbContext : AbpDbContext<MyProjectNameDbContext>
{

@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.Data;
namespace MyCompanyName.MyProjectName.Server.Data;
public class MyProjectNameDbContextFactory : IDesignTimeDbContextFactory<MyProjectNameDbContext>
{

@ -7,7 +7,7 @@ using Volo.Abp.Identity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.TenantManagement;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.Data;
namespace MyCompanyName.MyProjectName.Server.Data;
public class MyProjectNameDbMigrationService : ITransientDependency
{

@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Volo.Abp.DependencyInjection;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.Data;
namespace MyCompanyName.MyProjectName.Server.Data;
public class MyProjectNameEFCoreDbSchemaMigrator : ITransientDependency
{

@ -9,7 +9,7 @@ using Volo.Abp.OpenIddict.Applications;
using Volo.Abp.PermissionManagement;
using Volo.Abp.Uow;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.Data;
namespace MyCompanyName.MyProjectName.Server.Data;
/* Creates initial data that is needed to property run the application
* and make client-to-server communication possible.

@ -5,12 +5,12 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.Data;
using MyCompanyName.MyProjectName.Server.Data;
using Volo.Abp.EntityFrameworkCore;
#nullable disable
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.Migrations
namespace MyCompanyName.MyProjectName.Server.Migrations
{
[DbContext(typeof(MyProjectNameDbContext))]
[Migration("20221205080257_Initial")]

@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.Migrations
namespace MyCompanyName.MyProjectName.Server.Migrations
{
/// <inheritdoc />
public partial class Initial : Migration

@ -4,12 +4,12 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.Data;
using MyCompanyName.MyProjectName.Server.Data;
using Volo.Abp.EntityFrameworkCore;
#nullable disable
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.Migrations
namespace MyCompanyName.MyProjectName.Server.Migrations
{
[DbContext(typeof(MyProjectNameDbContext))]
partial class MyProjectNameDbContextModelSnapshot : ModelSnapshot

@ -87,7 +87,7 @@
<PrivateAssets>compile; contentFiles; build; buildMultitargeting; buildTransitive; analyzers; native</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Client\MyCompanyName.MyProjectName.Blazor.WebAssembly.Client.csproj" />
<ProjectReference Include="..\Shared\MyCompanyName.MyProjectName.Blazor.WebAssembly.Shared.csproj" />
@ -104,15 +104,4 @@
<Content Remove="$(UserProfile)\.nuget\packages\*\*\contentFiles\any\*\*.abppkg*.json" />
</ItemGroup>
<ItemGroup>
<Reference Include="Volo.Abp.AspNetCore.MultiTenancy">
<HintPath>..\..\..\..\..\..\framework\src\Volo.Abp.AspNetCore.MultiTenancy\bin\Debug\net7.0\Volo.Abp.AspNetCore.MultiTenancy.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="Pages\Error.cshtml" />
</ItemGroup>
</Project>

@ -3,10 +3,10 @@ using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.OpenApi.Models;
using MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.Data;
using MyCompanyName.MyProjectName.Blazor.WebAssembly.Shared;
using MyCompanyName.MyProjectName.Blazor.WebAssembly.Shared.Localization;
using MyCompanyName.MyProjectName.Blazor.WebAssembly.Shared.MultiTenancy;
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;
@ -46,12 +46,12 @@ using Volo.Abp.UI.Navigation.Urls;
using Volo.Abp.Uow;
using Volo.Abp.VirtualFileSystem;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Server;
namespace MyCompanyName.MyProjectName.Server;
[DependsOn(
typeof(MyProjectNameSharedModule),
// ABP Framework packages
typeof(AbpAspNetCoreMvcModule),
typeof(AbpAspNetCoreMultiTenancyModule),
@ -108,7 +108,7 @@ public class MyProjectNameServerModule : AbpModule
typeof(MyProjectNameResource)
);
});
PreConfigure<OpenIddictBuilder>(builder =>
{
builder.AddValidation(options =>
@ -119,17 +119,17 @@ public class MyProjectNameServerModule : AbpModule
});
});
}
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();
@ -142,12 +142,12 @@ public class MyProjectNameServerModule : AbpModule
ConfigureDataProtection(context);
ConfigureEfCore(context);
}
private void ConfigureAuthentication(ServiceConfigurationContext context)
{
context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
}
private void ConfigureBundles()
{
Configure<AbpBundlingOptions>(options =>
@ -158,7 +158,7 @@ public class MyProjectNameServerModule : AbpModule
);
});
}
private void ConfigureMultiTenancy()
{
Configure<AbpMultiTenancyOptions>(options =>
@ -166,7 +166,7 @@ public class MyProjectNameServerModule : AbpModule
options.IsEnabled = MultiTenancyConsts.IsEnabled;
});
}
private void ConfigureUrls(IConfiguration configuration)
{
Configure<AppUrlOptions>(options =>
@ -188,7 +188,7 @@ public class MyProjectNameServerModule : AbpModule
}
});
}
private void ConfigureAutoApiControllers()
{
Configure<AbpAspNetCoreMvcOptions>(options =>
@ -196,7 +196,7 @@ public class MyProjectNameServerModule : AbpModule
options.ConventionalControllers.Create(typeof(MyProjectNameServerModule).Assembly);
});
}
private void ConfigureSwagger(IServiceCollection services, IConfiguration configuration)
{
services.AddAbpSwaggerGenWithOAuth(
@ -212,7 +212,7 @@ public class MyProjectNameServerModule : AbpModule
options.CustomSchemaIds(type => type.FullName);
});
}
private void ConfigureAutoMapper(ServiceConfigurationContext context)
{
context.Services.AddAutoMapperObjectMapper<MyProjectNameServerModule>();
@ -225,7 +225,7 @@ public class MyProjectNameServerModule : AbpModule
options.AddMaps<MyProjectNameServerModule>(/* validate: true */);
});
}
private void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration)
{
context.Services.AddCors(options =>
@ -247,12 +247,12 @@ public class MyProjectNameServerModule : AbpModule
});
});
}
private void ConfigureDataProtection(ServiceConfigurationContext context)
{
context.Services.AddDataProtection().SetApplicationName("MyProjectName");
}
private void ConfigureEfCore(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<MyProjectNameDbContext>(options =>
@ -263,7 +263,7 @@ public class MyProjectNameServerModule : AbpModule
*/
options.AddDefaultRepositories(includeAllEntities: true);
});
Configure<AbpDbContextOptions>(options =>
{
options.Configure(configurationContext =>
@ -271,7 +271,7 @@ public class MyProjectNameServerModule : AbpModule
configurationContext.UseSqlServer();
});
});
//<TEMPLATE-REMOVE IF-NOT='dbms:SQLite'>
Configure<AbpUnitOfWorkDefaultOptions>(options =>
{
@ -279,24 +279,24 @@ public class MyProjectNameServerModule : AbpModule
});
//</TEMPLATE-REMOVE>
}
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();
@ -304,32 +304,32 @@ public class MyProjectNameServerModule : AbpModule
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");
}
}
}
}

@ -1,6 +1,6 @@
using AutoMapper;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.ObjectMapping;
namespace MyCompanyName.MyProjectName.Server.ObjectMapping;
public class MyProjectNameAutoMapperProfile : Profile
{

@ -1,6 +1,5 @@
using Microsoft.AspNetCore.ResponseCompression;
using MyCompanyName.MyProjectName.Blazor.WebAssembly.Server;
using MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.Data;
using MyCompanyName.MyProjectName.Server;
using MyCompanyName.MyProjectName.Server.Data;
using Serilog;
using Serilog.Events;
using Volo.Abp.Data;
@ -36,7 +35,7 @@ public class Program
try
{
var builder = WebApplication.CreateBuilder(args);
builder.Host.AddAppSettingsSecretsJson()
.UseAutofac()
@ -48,13 +47,13 @@ public class Program
}
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;
@ -65,7 +64,7 @@ public class Program
{
throw;
}
Log.Fatal(ex, "MyCompanyName.MyProjectName terminated unexpectedly!");
return 1;
}
@ -74,10 +73,9 @@ public class Program
Log.CloseAndFlush();
}
}
private static bool IsMigrateDatabase(string[] args)
{
return args.Any(x => x.Contains("--migrate-database", StringComparison.OrdinalIgnoreCase));
}
}

@ -5,7 +5,7 @@
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.dll" stdoutLogEnabled="false" stdoutLogFile=".\Logs\stdout" hostingModel="inprocess" />
<aspNetCore processPath="dotnet" arguments=".\MyCompanyName.MyProjectName.Server.dll" stdoutLogEnabled="false" stdoutLogFile=".\Logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
<system.webServer>

@ -1,6 +1,6 @@
using Volo.Abp.Localization;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Shared.Localization;
namespace MyCompanyName.MyProjectName.Shared.Localization;
[LocalizationResourceName("MyProjectName")]
public class MyProjectNameResource

@ -1,4 +1,4 @@
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Shared.MultiTenancy;
namespace MyCompanyName.MyProjectName.Shared.MultiTenancy;
public static class MultiTenancyConsts
{

@ -1,4 +1,4 @@
using MyCompanyName.MyProjectName.Blazor.WebAssembly.Shared.Localization;
using MyCompanyName.MyProjectName.Shared.Localization;
using Volo.Abp.Localization;
using Volo.Abp.Localization.ExceptionHandling;
using Volo.Abp.Modularity;
@ -6,7 +6,7 @@ using Volo.Abp.Validation;
using Volo.Abp.Validation.Localization;
using Volo.Abp.VirtualFileSystem;
namespace MyCompanyName.MyProjectName.Blazor.WebAssembly.Shared;
namespace MyCompanyName.MyProjectName.Shared;
[DependsOn(
typeof(AbpValidationModule)

@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyCompanyName.MyProjectName
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyCompanyName.MyProjectName.Blazor.WebAssembly.Shared", "MyCompanyName.MyProjectName.Blazor.WebAssembly\Shared\MyCompanyName.MyProjectName.Blazor.WebAssembly.Shared.csproj", "{430B37D2-9008-4704-8FC7-77A2DF3F3587}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.Mongo", "MyCompanyName.MyProjectName.Blazor.WebAssembly\Server.Mongo\MyCompanyName.MyProjectName.Blazor.WebAssembly.Server.Mongo.csproj", "{36773181-4623-41E0-B456-67C1EEC03A2E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -63,6 +65,10 @@ Global
{430B37D2-9008-4704-8FC7-77A2DF3F3587}.Debug|Any CPU.Build.0 = Debug|Any CPU
{430B37D2-9008-4704-8FC7-77A2DF3F3587}.Release|Any CPU.ActiveCfg = Release|Any CPU
{430B37D2-9008-4704-8FC7-77A2DF3F3587}.Release|Any CPU.Build.0 = Release|Any CPU
{36773181-4623-41E0-B456-67C1EEC03A2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{36773181-4623-41E0-B456-67C1EEC03A2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{36773181-4623-41E0-B456-67C1EEC03A2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{36773181-4623-41E0-B456-67C1EEC03A2E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save