diff --git a/docs/en/Blog-Posts/2020-10-15 v3_3_Preview/POST.md b/docs/en/Blog-Posts/2020-10-15 v3_3_Preview/POST.md new file mode 100644 index 0000000000..b42e17e865 --- /dev/null +++ b/docs/en/Blog-Posts/2020-10-15 v3_3_Preview/POST.md @@ -0,0 +1,238 @@ +# ABP Framework 3.3 RC Has Been Published + +We have released the [ABP Framework](https://abp.io/) (and the [ABP Commercial](https://commercial.abp.io/)) `3.3.0-rc.1` today. This blog post introduces the new features and important changes in the new version. + +## What's new with the ABP Framework 3.3 + +### The Blazor UI + +We had released an experimental early preview version of the Blazor UI with the [previous version](https://blog.abp.io/abp/ABP-Framework-ABP-Commercial-3.2-RC-With-The-New-Blazor-UI). In this version, we've completed most of the fundamental infrastructure features and the application modules (like identity and tenant management). + +It currently has almost the same functionalities as the other UI types (Angular & MVC / Razor Pages). + +**Example screenshot**: User management page of the Blazor UI + +![abp-blazor-ui](abp-blazor-ui.png) + +> We've adapted the [Lepton Theme](https://commercial.abp.io/themes) for the ABP Commercial, see the related section below. + +We are still working on the fundamentals. So, the next version may introduce breaking changes of the Blazor UI. We will work hard to keep them with the minimal effect on your application code. + +#### Breaking Changes on the Blazor UI + +There are some breaking changes with the Blazor UI. If you've built an application and upgrade it, your application might not properly work. See [the migration guide](https://github.com/abpframework/abp/blob/dev/docs/en/Migration-Guides/BlazorUI-3_3.md) for the changes you need to do after upgrading your application. + +### Automatic Validation for AntiForgery Token for HTTP APIs + +Starting with the version 3.3, all your HTTP API endpoints are **automatically protected** against CSRF attacks, unless you disable it for your application. + +[See the documentation](https://github.com/abpframework/abp/blob/dev/docs/en/CSRF-Anti-Forgery.md) to understand why you need it and how ABP Framework solves the problem. + +### Rebus Integration Package for the Distributed Event Bus + +[Rebus](https://github.com/rebus-org/Rebus) describes itself as "Simple and lean service bus implementation for .NET". There are a lot of integration packages like RabbitMQ and Azure Service Bus for the Rebus. The new [Volo.Abp.EventBus.Rebus](https://www.nuget.org/packages/Volo.Abp.EventBus.Rebus) package allows you to use the Rebus as the [distributed event bus](https://docs.abp.io/en/abp/latest/Distributed-Event-Bus) for the ABP Framework. + +See [the documentation](https://github.com/abpframework/abp/blob/dev/docs/en/Distributed-Event-Bus-Rebus-Integration.md) to learn how to use Rebus with the ABP Framework. + +### Async Repository LINQ Extension Methods + +You have a problem when you want to use **Async LINQ Extension Methods** (e.g. `FirstOrDefaultAsync(...)`) in your **domain** and **application** layers. These async methods are **not included in the standard LINQ extension methods**. Those are defined by the [Microsoft.EntityFrameworkCore](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore) NuGet package (see [the code](https://github.com/dotnet/efcore/blob/main/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs)). To be able to use these `async` methods, you need to reference to the `Microsoft.EntityFrameworkCore` package. + +If you don't want to depend on the EF Core in your business layer, then ABP Framework provides the `IAsyncQueryableExecuter` service to execute your queries asynchronously without depending on the EF Core package. You can see [the documentation](https://docs.abp.io/en/abp/latest/Repositories#option-3-iasyncqueryableexecuter) to get more information about this service. + +ABP Framework version 3.3 takes this one step further and allows you to directly execute the async LINQ extension methods on the `IRepository` interface. + +**Example: Use `CountAsync` and `FirstOrDefaultAsync` methods on the repositories** + +````csharp +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; + +namespace MyCompanyName.MyProjectName +{ + public class BookAppService : ApplicationService, IBookAppService + { + private readonly IRepository _bookRepository; + + public BookAppService(IRepository bookRepository) + { + _bookRepository = bookRepository; + } + + public async Task DemoAsync() + { + var countAll = await _bookRepository + .CountAsync(); + + var count = await _bookRepository + .CountAsync(x => x.Name.Contains("A")); + + var book1984 = await _bookRepository + .FirstOrDefaultAsync(x => x.Name == "1984"); + } + } +} +```` + +All the standard LINQ methods are supported: *AllAsync, AnyAsync, AverageAsync, ContainsAsync, CountAsync, FirstAsync, FirstOrDefaultAsync, LastAsync, LastOrDefaultAsync, LongCountAsync, MaxAsync, MinAsync, SingleAsync, SingleOrDefaultAsync, SumAsync, ToArrayAsync, ToListAsync*. + +This approach still has a limitation. You need to execute the extension method directly on the repository object. For example, the below usage is **not supported**: + +````csharp +var count = await _bookRepository.Where(x => x.Name.Contains("A")).CountAsync(); +```` + +This is because the object returned from the `Where` method is not a repository object, it is a standard `IQueryable`. In such cases, you can still use the `IAsyncQueryableExecuter`: + +````csharp +var count = await AsyncExecuter.CountAsync( + _bookRepository.Where(x => x.Name.Contains("A")) +); +```` + +`AsyncExecuter` has all the standard extension methods, so you don't have any restriction here. See [the repository documentation](https://docs.abp.io/en/abp/latest/Repositories#iqueryable-async-operations) for all the options you have. + +> ABP Framework does its best to not depend on the EF Core and still be able to use the async LINQ extension methods. However, there is no problem to depend on the EF Core for your application, you can add the `Microsoft.EntityFrameworkCore` NuGet package and use the native methods. + +### Stream Support for the Application Service Methods + +[Application services](https://docs.abp.io/en/abp/latest/Application-Services) are consumed by clients and the parameters and return values (typically [Data Transfer Objects](https://docs.abp.io/en/abp/latest/Data-Transfer-Objects)). In case of the client is a remote application, then these objects should be serialized & deserialized. + +Until the version 3.3, we hadn't suggest to use the `Stream` in the application service contracts, since it is not serializable/deserializable. However, with the version 3.3, ABP Framework properly supports this scenario by introducing the new `IRemoteStreamContent` interface. + +Example: An application service that can get or return streams + +````csharp +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Services; +using Volo.Abp.Content; + +namespace MyProject.Test +{ + public interface ITestAppService : IApplicationService + { + Task Upload(Guid id, IRemoteStreamContent streamContent); + Task Download(Guid id); + } +} +```` + +The implementation can be as shown below: + +````csharp +using System; +using System.IO; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Services; +using Volo.Abp.Content; + +namespace MyProject.Test +{ + public class TestAppService : ApplicationService, ITestAppService + { + public Task Download(Guid id) + { + var fs = new FileStream("C:\\Temp\\" + id + ".blob", FileMode.OpenOrCreate); + return Task.FromResult( + (IRemoteStreamContent) new RemoteStreamContent(fs) { + ContentType = "application/octet-stream" + } + ); + } + + public async Task Upload(Guid id, IRemoteStreamContent streamContent) + { + using (var fs = new FileStream("C:\\Temp\\" + id + ".blob", FileMode.Create)) + { + await streamContent.GetStream().CopyToAsync(fs); + await fs.FlushAsync(); + } + } + } +} +```` + +> This is just a demo code. Do it better in your production code :) + +Thanks to [@alexandru-bagu](https://github.com/alexandru-bagu) for the great contribution! + +### Other Changes + +* Upgraded all the .NET Core / ASP.NET Core related packages to the version 3.1.8. If you have additional dependencies to the .NET Core / ASP.NET Core related packages, we suggest you to updates your packages to the version 3.1.8 to have the latest bug and security fixes published by Microsoft. +* The blogging module now uses the [BLOB Storing](https://docs.abp.io/en/abp/latest/Blob-Storing) system to store images & files of the blog posts. If you are using this module, then you need to manually migrate the local files to the BLOB Storing system after the upgrade. +* The Angular UI is now redirecting to the profile management page of the MVC UI instead of using its own UI, if you've configured the authorization code flow (which is default since the version 3.2.0). + +## What's new with the ABP Commercial 3.3 + +### The Blazor UI + +We have good news for the ABP Commercial Blazor UI too. We have implemented the [Lepton Theme](https://commercial.abp.io/themes) integration, so it is now available with the Blazor UI. Also, implemented most of the fundamental [modules](https://commercial.abp.io/modules). + +**A screenshot from the ABP Commercial startup template with the Blazor UI** + +![abp-commercial-blazor-ui](abp-commercial-blazor-ui.png) + +There are still missing features and modules. However, we are working on it to have a more complete version in the next release. + +#### Breaking Changes on the Blazor UI + +There are some breaking changes with the Blazor UI. If you've built an application and upgrade it, your application might not properly work. See the [ABP Commercial Blazor UI v 3.3 Migration Guide](https://github.com/abpio/abp-commercial-docs/blob/dev/en/migration-guides/blazor-ui-3_3.md) for the changes you need to do after upgrading your application. + +### Multi-Tenant Social Logins + +[Account module](https://commercial.abp.io/modules/Volo.Account.Pro) now supports to manage the social/external logins in the UI. You can **enable/disable** and **set options** in the settings page. It also supports to use **different credentials for the tenants** and it is also **configured on the runtime**. + +![abp-commercial-setting-account-external-logins](abp-commercial-setting-account-external-logins.png) + +### Linked Accounts + +Linked user system allows you to link other accounts (including account in a different tenant) with your account, so you can switch between different accounts with a single-click. It is practical since you no longer need to logout and login again with entering the credentials of the target account. + +To manage the linked accounts, go to the profile management page from the user menu; + +![abp-commercial-linked-users](abp-commercial-linked-users.png) + +### Paypal & Stripe Integrations + +The [Payment Module](https://commercial.abp.io/modules/Volo.Payment) was supporting PayU and 2Checkout providers until the version 3.3. It's now integrated to PayPal and Stripe. See the [technical documentation](https://docs.abp.io/en/commercial/latest/modules/payment) to learn how to use it. + +### ABP Suite Improvements + +We've done a lot of small improvements for the [ABP Suite](https://commercial.abp.io/tools/suite). Some of the enhancements are; + +* Show the previously installed modules as *installed* on the module list. +* Switch between the latest stable, the latest [preview](https://docs.abp.io/en/abp/latest/Previews) and the latest [nightly build](https://docs.abp.io/en/abp/latest/Nightly-Builds) versions of the ABP related packages. +* Moved the file that stores the *previously created entities* into the solution folder to allow you to store it in your source control system. + +### Others + +* Added an option to the Account Module to show reCAPTCHA on the login & the registration forms. + +Besides the new features introduced in this post, we've done a lot of small other enhancements and bug fixes to provide a better development experience and increase the developer productivity. + +## New Articles + +The core ABP Framework team & the community continue to publish new articles on the ABP Community web site. The recently published articles are; + +* [Replacing Email Templates and Sending Emails](https://community.abp.io/articles/replacing-email-templates-and-sending-emails-jkeb8zzh) (by [@EngincanV](https://community.abp.io/members/EngincanV)) +* [How to Add Custom Properties to the User Entity](https://community.abp.io/articles/how-to-add-custom-property-to-the-user-entity-6ggxiddr) (by [@berkansasmaz](https://community.abp.io/members/berkansasmaz)) +* [Using the AdminLTE Theme with the ABP Framework MVC / Razor Pages UI](https://community.abp.io/articles/using-the-adminlte-theme-with-the-abp-framework-mvc-razor-pages-ui-gssbhb7m) (by [@mucahiddanis](https://community.abp.io/members/mucahiddanis)) +* [Using DevExtreme Angular Components With the ABP Framework](https://community.abp.io/articles/using-devextreme-angular-components-with-the-abp-framework-x5nyvj3i) (by [@bunyamin](https://community.abp.io/members/bunyamin)) + +It is appreciated if you want to [submit an article](https://community.abp.io/articles/submit) related to the ABP Framework. + +## About the Next Release + +The next version will be `4.0.0`. We are releasing a major version, since we will move the ABP Framework to .NET 5.0. We see that for most of the applications this will not be a breaking change and we hope you easily upgrade to it. + +The planned 4.0.0-rc.1 (Release Candidate) version date is **November 11**, just after the Microsoft releases the .NET 5.0 final. The planned 4.0.0 final release date is **November 26**. + +Follow the [GitHub milestones](https://github.com/abpframework/abp/milestones) for all the planned ABP Framework version release dates. + +## Feedback + +Please check out the ABP Framework 3.3.0 RC and [provide feedback](https://github.com/abpframework/abp/issues/new) to help us to release a more stable version. The planned release date for the [3.3.0 final](https://github.com/abpframework/abp/milestone/44) version is October 27th. diff --git a/docs/en/Blog-Posts/2020-10-15 v3_3_Preview/abp-blazor-ui.png b/docs/en/Blog-Posts/2020-10-15 v3_3_Preview/abp-blazor-ui.png new file mode 100644 index 0000000000..ea61f2a488 Binary files /dev/null and b/docs/en/Blog-Posts/2020-10-15 v3_3_Preview/abp-blazor-ui.png differ diff --git a/docs/en/Blog-Posts/2020-10-15 v3_3_Preview/abp-commercial-blazor-ui.png b/docs/en/Blog-Posts/2020-10-15 v3_3_Preview/abp-commercial-blazor-ui.png new file mode 100644 index 0000000000..8da48af76e Binary files /dev/null and b/docs/en/Blog-Posts/2020-10-15 v3_3_Preview/abp-commercial-blazor-ui.png differ diff --git a/docs/en/Blog-Posts/2020-10-15 v3_3_Preview/abp-commercial-linked-users.png b/docs/en/Blog-Posts/2020-10-15 v3_3_Preview/abp-commercial-linked-users.png new file mode 100644 index 0000000000..ef957aecd5 Binary files /dev/null and b/docs/en/Blog-Posts/2020-10-15 v3_3_Preview/abp-commercial-linked-users.png differ diff --git a/docs/en/Blog-Posts/2020-10-15 v3_3_Preview/abp-commercial-setting-account-external-logins.png b/docs/en/Blog-Posts/2020-10-15 v3_3_Preview/abp-commercial-setting-account-external-logins.png new file mode 100644 index 0000000000..8be08af686 Binary files /dev/null and b/docs/en/Blog-Posts/2020-10-15 v3_3_Preview/abp-commercial-setting-account-external-logins.png differ diff --git a/docs/en/Migration-Guides/BlazorUI-3_3.md b/docs/en/Migration-Guides/BlazorUI-3_3.md new file mode 100644 index 0000000000..8a14481912 --- /dev/null +++ b/docs/en/Migration-Guides/BlazorUI-3_3.md @@ -0,0 +1,13 @@ +# Migration Guide for the Blazor UI from the v3.2 to the v3.3 + +## Startup Template Changes + +* Remove `Volo.Abp.Account.Blazor` NuGet package from your `.Blazor.csproj` and add `Volo.Abp.TenantManagement.Blazor` NuGet package. +* Remove the ``typeof(AbpAccountBlazorModule)`` from the dependency list of *YourProjectBlazorModule* class and add the `typeof(AbpTenantManagementBlazorModule)`. +* Add `@using Volo.Abp.BlazoriseUI` and `@using Volo.Abp.BlazoriseUI.Components` into the `_Imports.razor` file. +* Remove the `div` with `id="blazor-error-ui"` (with its contents) from the `wwwroot/index.html ` file, since the ABP Framework now shows error messages as a better message box. + +## BlazoriseCrudPageBase to AbpCrudPageBase + +Renamed `BlazoriseCrudPageBase` to `AbpCrudPageBase`. Just update the usages. It also has some changes, you may need to update method calls/usages manually. + diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/AbpExceptionHandlingLogger.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/AbpExceptionHandlingLogger.cs index 445ccbaba0..2190489d4c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/AbpExceptionHandlingLogger.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/AbpExceptionHandlingLogger.cs @@ -4,10 +4,9 @@ using Microsoft.Extensions.Logging; namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling { - public class AbpExceptionHandlingLogger : ILogger, IDisposable + public class AbpExceptionHandlingLogger : ILogger { private readonly IServiceCollection _serviceCollection; - private IServiceScope _serviceScope; private IUserExceptionInformer _userExceptionInformer; public AbpExceptionHandlingLogger(IServiceCollection serviceCollection) @@ -39,7 +38,7 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling return; } - _userExceptionInformer.InformAsync(new UserExceptionInformerContext(exception)); + _userExceptionInformer.Inform(new UserExceptionInformerContext(exception)); } protected virtual void TryInitialize() @@ -50,8 +49,7 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling return; } - _serviceScope = serviceProvider.CreateScope(); - _userExceptionInformer = _serviceScope.ServiceProvider.GetRequiredService(); + _userExceptionInformer = serviceProvider.GetRequiredService(); } public virtual bool IsEnabled(LogLevel logLevel) @@ -63,10 +61,5 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling { return NullDisposable.Instance; } - - public virtual void Dispose() - { - _serviceScope?.Dispose(); - } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/AbpExceptionHandlingLoggerProvider.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/AbpExceptionHandlingLoggerProvider.cs index d295559284..85eb021284 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/AbpExceptionHandlingLoggerProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/AbpExceptionHandlingLoggerProvider.cs @@ -32,7 +32,7 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling public void Dispose() { - _logger.Dispose(); + } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/IUserExceptionInformer.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/IUserExceptionInformer.cs index 4399e706ec..2abbe3667b 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/IUserExceptionInformer.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/IUserExceptionInformer.cs @@ -1,10 +1,7 @@ -using System; -using System.Threading.Tasks; - -namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling +namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling { public interface IUserExceptionInformer { - Task InformAsync(UserExceptionInformerContext context); + void Inform(UserExceptionInformerContext context); } } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/UserExceptionInformer.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/UserExceptionInformer.cs index 80f80c675a..c409c38319 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/UserExceptionInformer.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ExceptionHandling/UserExceptionInformer.cs @@ -1,5 +1,7 @@ using System; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.AspNetCore.ExceptionHandling; using Volo.Abp.DependencyInjection; using Volo.Abp.Http; @@ -9,19 +11,32 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling { public class UserExceptionInformer : IUserExceptionInformer, ITransientDependency { + public ILogger Logger { get; set; } protected IUiMessageService MessageService { get; } protected IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; } - public UserExceptionInformer(IUiMessageService messageService, IExceptionToErrorInfoConverter exceptionToErrorInfoConverter) + public UserExceptionInformer( + IUiMessageService messageService, + IExceptionToErrorInfoConverter exceptionToErrorInfoConverter) { MessageService = messageService; ExceptionToErrorInfoConverter = exceptionToErrorInfoConverter; + Logger = NullLogger.Instance; } - public virtual async Task InformAsync(UserExceptionInformerContext context) + public void Inform(UserExceptionInformerContext context) { var errorInfo = GetErrorInfo(context); - await ShowErrorInfoAsync(errorInfo); + + if (errorInfo.Details.IsNullOrEmpty()) + { + //TODO: Should we introduce MessageService.Error (sync) method instead of such a usage (without await)..? + MessageService.ErrorAsync(errorInfo.Message); + } + else + { + MessageService.ErrorAsync(errorInfo.Details, errorInfo.Message); + } } protected virtual RemoteServiceErrorInfo GetErrorInfo(UserExceptionInformerContext context) @@ -33,17 +48,5 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.ExceptionHandling return ExceptionToErrorInfoConverter.Convert(context.Exception, false); } - - protected virtual async Task ShowErrorInfoAsync(RemoteServiceErrorInfo errorInfo) - { - if (errorInfo.Details.IsNullOrEmpty()) - { - await MessageService.ErrorAsync(errorInfo.Message); - } - else - { - await MessageService.ErrorAsync(errorInfo.Details, errorInfo.Message); - } - } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentTenantAccessor.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/MultiTenancy/WebAssemblyCurrentTenantAccessor.cs similarity index 80% rename from framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentTenantAccessor.cs rename to framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/MultiTenancy/WebAssemblyCurrentTenantAccessor.cs index eb0ee781ad..3857db2b36 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentTenantAccessor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/MultiTenancy/WebAssemblyCurrentTenantAccessor.cs @@ -1,7 +1,7 @@ using Volo.Abp.DependencyInjection; using Volo.Abp.MultiTenancy; -namespace Volo.Abp.AspNetCore.Components.WebAssembly +namespace Volo.Abp.AspNetCore.Components.WebAssembly.MultiTenancy { [Dependency(ReplaceServices = true)] public class WebAssemblyCurrentTenantAccessor : ICurrentTenantAccessor, ISingletonDependency diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyRemoteTenantStore.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/MultiTenancy/WebAssemblyRemoteTenantStore.cs similarity index 54% rename from framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyRemoteTenantStore.cs rename to framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/MultiTenancy/WebAssemblyRemoteTenantStore.cs index ebe170cfa8..7e132db9c9 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyRemoteTenantStore.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/MultiTenancy/WebAssemblyRemoteTenantStore.cs @@ -6,44 +6,55 @@ using Volo.Abp.Http.Client.DynamicProxying; using Volo.Abp.MultiTenancy; using Volo.Abp.Threading; -namespace Volo.Abp.AspNetCore.Components.WebAssembly +namespace Volo.Abp.AspNetCore.Components.WebAssembly.MultiTenancy { public class WebAssemblyRemoteTenantStore : ITenantStore, ITransientDependency { protected IHttpClientProxy Proxy { get; } + protected WebAssemblyRemoteTenantStoreCache Cache { get; } public WebAssemblyRemoteTenantStore( - IHttpClientProxy proxy) + IHttpClientProxy proxy, + WebAssemblyRemoteTenantStoreCache cache) { Proxy = proxy; + Cache = cache; } public async Task FindAsync(string name) { - //TODO: Cache + var cached = Cache.Find(name); + if (cached != null) + { + return cached; + } - return CreateTenantConfiguration(await Proxy.Service.FindTenantByNameAsync(name)); + var tenant = CreateTenantConfiguration(await Proxy.Service.FindTenantByNameAsync(name)); + Cache.Set(tenant); + return tenant; } public async Task FindAsync(Guid id) { - //TODO: Cache + var cached = Cache.Find(id); + if (cached != null) + { + return cached; + } - return CreateTenantConfiguration(await Proxy.Service.FindTenantByIdAsync(id)); + var tenant = CreateTenantConfiguration(await Proxy.Service.FindTenantByIdAsync(id)); + Cache.Set(tenant); + return tenant; } public TenantConfiguration Find(string name) { - //TODO: Cache - - return AsyncHelper.RunSync(async () => CreateTenantConfiguration(await Proxy.Service.FindTenantByNameAsync(name))); + return AsyncHelper.RunSync(() => FindAsync(name)); } public TenantConfiguration Find(Guid id) { - //TODO: Cache - - return AsyncHelper.RunSync(async () => CreateTenantConfiguration(await Proxy.Service.FindTenantByIdAsync(id))); + return AsyncHelper.RunSync(() => FindAsync(id)); } protected virtual TenantConfiguration CreateTenantConfiguration(FindTenantResultDto tenantResultDto) @@ -55,15 +66,5 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly return new TenantConfiguration(tenantResultDto.TenantId.Value, tenantResultDto.Name); } - - protected virtual string CreateCacheKey(string tenantName) - { - return $"RemoteTenantStore_Name_{tenantName}"; - } - - protected virtual string CreateCacheKey(Guid tenantId) - { - return $"RemoteTenantStore_Id_{tenantId:N}"; - } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/MultiTenancy/WebAssemblyRemoteTenantStoreCache.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/MultiTenancy/WebAssemblyRemoteTenantStoreCache.cs new file mode 100644 index 0000000000..e1c5112e02 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/MultiTenancy/WebAssemblyRemoteTenantStoreCache.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Volo.Abp.DependencyInjection; +using Volo.Abp.MultiTenancy; + +namespace Volo.Abp.AspNetCore.Components.WebAssembly.MultiTenancy +{ + public class WebAssemblyRemoteTenantStoreCache : IScopedDependency + { + protected readonly List CachedTenants = new List(); + + public virtual TenantConfiguration Find(string name) + { + return CachedTenants.FirstOrDefault(t => t.Name == name); + } + + public virtual TenantConfiguration Find(Guid id) + { + return CachedTenants.FirstOrDefault(t => t.Id == id); + } + + public virtual void Set(TenantConfiguration tenant) + { + var existingTenant = Find(tenant.Id); + if (existingTenant != null) + { + existingTenant.Name = tenant.Name; + return; + } + + CachedTenants.Add(tenant); + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/NullUiMessageService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/NullUiMessageService.cs deleted file mode 100644 index 2a00d29ec5..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/NullUiMessageService.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Threading.Tasks; -using Volo.Abp.DependencyInjection; - -namespace Volo.Abp.AspNetCore.Components.WebAssembly -{ - public class NullUiMessageService : IUiMessageService, ITransientDependency - { - public Task InfoAsync(string message, string title = null, Action options = null) - { - return Task.CompletedTask; - } - - public Task SuccessAsync(string message, string title = null, Action options = null) - { - return Task.CompletedTask; - } - - public Task WarnAsync(string message, string title = null, Action options = null) - { - return Task.CompletedTask; - } - - public Task ErrorAsync(string message, string title = null, Action options = null) - { - return Task.CompletedTask; - } - - public Task ConfirmAsync(string message, string title = null, Action options = null) - { - return Task.FromResult(true); - } - } -} diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/SimpleUiMessageService.cs similarity index 87% rename from framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageService.cs rename to framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/SimpleUiMessageService.cs index 93970de348..8f43b3fdcd 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/UiMessageService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/SimpleUiMessageService.cs @@ -5,12 +5,11 @@ using Volo.Abp.DependencyInjection; namespace Volo.Abp.AspNetCore.Components.WebAssembly { - //TODO: Implement with sweetalert in a new package - public class UiMessageService : IUiMessageService, ITransientDependency + public class SimpleUiMessageService : IUiMessageService, ITransientDependency { protected IJSRuntime JsRuntime { get; } - public UiMessageService(IJSRuntime jsRuntime) + public SimpleUiMessageService(IJSRuntime jsRuntime) { JsRuntime = jsRuntime; } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs index d309d4858a..8846473d96 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs @@ -25,6 +25,7 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App SwitchDatabaseProvider(context, steps); DeleteUnrelatedProjects(context, steps); RandomizeSslPorts(context, steps); + RandomizeStringEncryption(context, steps); UpdateNuGetConfig(context, steps); CleanupFolderHierarchy(context, steps); @@ -185,6 +186,11 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App ); } + private static void RandomizeStringEncryption(ProjectBuildContext context, List steps) + { + steps.Add(new RandomizeStringEncryptionStep()); + } + private static void UpdateNuGetConfig(ProjectBuildContext context, List steps) { steps.Add(new UpdateNuGetConfigStep("/aspnet-core/NuGet.Config")); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/RandomizeStringEncryptionStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/RandomizeStringEncryptionStep.cs new file mode 100644 index 0000000000..6fc2bafc95 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/RandomizeStringEncryptionStep.cs @@ -0,0 +1,47 @@ +using System; +using System.Linq; +using System.Text; +using Volo.Abp.Cli.ProjectBuilding.Building; + +namespace Volo.Abp.Cli.ProjectBuilding.Templates +{ + public class RandomizeStringEncryptionStep: ProjectBuildPipelineStep + { + public override void Execute(ProjectBuildContext context) + { + var appSettings = context.Files + .Where(x => !x.IsDirectory && x.Name.EndsWith("appSettings.json", StringComparison.InvariantCultureIgnoreCase)) + .Where(x => x.Content.IndexOf("StringEncryption", StringComparison.InvariantCultureIgnoreCase) >= 0) + .ToList(); + + const string defaultPassPhrase = "gsKnGZ041HLL4IM8"; + var randomPassPhrase = GetRandomString(defaultPassPhrase.Length); + foreach (var appSetting in appSettings) + { + appSetting.NormalizeLineEndings(); + + var appSettingLines = appSetting.GetLines(); + for (var i = 0; i < appSettingLines.Length; i++) + { + if (appSettingLines[i].Contains("DefaultPassPhrase") && appSettingLines[i].Contains(defaultPassPhrase)) + { + appSettingLines[i] = appSettingLines[i].Replace(defaultPassPhrase, randomPassPhrase); + } + } + + appSetting.SetLines(appSettingLines); + } + } + + private static string GetRandomString(int length) + { + const string letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + var builder = new StringBuilder(); + for (var i = 0; i < length; i++) + { + builder.Append(letters[RandomHelper.GetRandom(0, letters.Length)]); + } + return builder.ToString(); + } + } +} diff --git a/framework/src/Volo.Abp.Security/Volo/Abp/Security/AbpSecurityModule.cs b/framework/src/Volo.Abp.Security/Volo/Abp/Security/AbpSecurityModule.cs index f62a9566c4..b1cdcb1097 100644 --- a/framework/src/Volo.Abp.Security/Volo/Abp/Security/AbpSecurityModule.cs +++ b/framework/src/Volo.Abp.Security/Volo/Abp/Security/AbpSecurityModule.cs @@ -1,9 +1,45 @@ -using Volo.Abp.Modularity; +using System; +using System.Text; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; +using Volo.Abp.Security.Encryption; namespace Volo.Abp.Security { public class AbpSecurityModule : AbpModule { + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + context.Services.Configure(options => + { + var keySize = configuration["StringEncryption:KeySize"]; + if (!keySize.IsNullOrWhiteSpace()) + { + if (int.TryParse(keySize, out var intValue)) + { + options.Keysize = intValue; + } + } + var defaultPassPhrase = configuration["StringEncryption:DefaultPassPhrase"]; + if (!defaultPassPhrase.IsNullOrWhiteSpace()) + { + options.DefaultPassPhrase = defaultPassPhrase; + } + + var initVectorBytes = configuration["StringEncryption:InitVectorBytes"]; + if (!initVectorBytes.IsNullOrWhiteSpace()) + { + options.InitVectorBytes = Encoding.ASCII.GetBytes(initVectorBytes);; + } + + var defaultSalt = configuration["StringEncryption:DefaultSalt"]; + if (!defaultSalt.IsNullOrWhiteSpace()) + { + options.DefaultSalt = Encoding.ASCII.GetBytes(defaultSalt);; + } + }); + } } } diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/_Imports.razor b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/_Imports.razor index 3fcce1e0d0..8daeb7f0f8 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/_Imports.razor +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/_Imports.razor @@ -9,5 +9,5 @@ @using MyCompanyName.MyProjectName.Blazor @using Blazorise @using Blazorise.DataGrid -@using Volo.Abp.BlazoriseUI; -@using Volo.Abp.BlazoriseUI.Components; \ No newline at end of file +@using Volo.Abp.BlazoriseUI +@using Volo.Abp.BlazoriseUI.Components \ No newline at end of file diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.json b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.json index 2cb4b81ab9..ab4349b9c6 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.json +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.json @@ -12,6 +12,9 @@ "Authority": "https://localhost:44301", "RequireHttpsMetadata": "true" }, + "StringEncryption": { + "DefaultPassPhrase": "gsKnGZ041HLL4IM8" + }, "Settings": { "Abp.Mailing.Smtp.Host": "127.0.0.1", "Abp.Mailing.Smtp.Port": "25", diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/appsettings.json b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/appsettings.json index 9b456d26b9..e62c32aa0c 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/appsettings.json +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.HostWithIds/appsettings.json @@ -10,6 +10,9 @@ "Authority": "https://localhost:44305", "RequireHttpsMetadata": "false" }, + "StringEncryption": { + "DefaultPassPhrase": "gsKnGZ041HLL4IM8" + }, "Settings": { "Abp.Mailing.Smtp.Host": "127.0.0.1", "Abp.Mailing.Smtp.Port": "25", diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/appsettings.json b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/appsettings.json index 887908f3db..b2fa57365a 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/appsettings.json +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/appsettings.json @@ -9,6 +9,9 @@ "Redis": { "Configuration": "127.0.0.1" }, + "StringEncryption": { + "DefaultPassPhrase": "gsKnGZ041HLL4IM8" + }, "Settings": { "Abp.Mailing.Smtp.Host": "127.0.0.1", "Abp.Mailing.Smtp.Port": "25", diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/appsettings.json b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/appsettings.json index f1a6421610..c89186b748 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/appsettings.json +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/appsettings.json @@ -15,5 +15,8 @@ "RequireHttpsMetadata": "true", "ClientId": "MyProjectName_Web", "ClientSecret": "1q2w3e*" + }, + "StringEncryption": { + "DefaultPassPhrase": "gsKnGZ041HLL4IM8" } } diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/appsettings.json b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/appsettings.json index 18dc17e87a..5f3d9b9bd8 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/appsettings.json +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web/appsettings.json @@ -16,6 +16,9 @@ } } }, + "StringEncryption": { + "DefaultPassPhrase": "gsKnGZ041HLL4IM8" + }, "Settings": { "Abp.Mailing.Smtp.Host": "127.0.0.1", "Abp.Mailing.Smtp.Port": "25",