diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs index d9cb936326..1c3806f272 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs @@ -175,7 +175,10 @@ namespace Volo.Abp.AspNetCore.Mvc parameterDescription.RouteInfo?.IsOptional ?? false, parameterDescription.RouteInfo?.DefaultValue, parameterDescription.RouteInfo?.Constraints?.Select(c => c.GetType().Name).ToArray(), - parameterDescription.Source.Id + parameterDescription.Source.Id, + parameterDescription.ModelMetadata.ContainerType != null + ? parameterDescription.ParameterDescriptor.Name + : string.Empty ) ); } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ModuleInfo.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ModuleInfo.cs index dfeabf6aed..fadd830c93 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ModuleInfo.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/ModuleInfo.cs @@ -7,5 +7,19 @@ public string Namespace { get; set; } public string DocumentUrl { get; set; } + + public string DisplayName { get; set; } + + public string ShortDescription { get; set; } + + public bool IsPro { get; set; } + + public bool EfCoreSupport { get; set; } + + public bool MongoDBSupport { get; set; } + + public bool AngularUi { get; set; } + + public bool MvcUi { get; set; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ParameterApiDescriptionModel.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ParameterApiDescriptionModel.cs index d1de33258f..257f06d3db 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ParameterApiDescriptionModel.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ParameterApiDescriptionModel.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Volo.Abp.Http.Modeling { @@ -19,12 +19,14 @@ namespace Volo.Abp.Http.Modeling public string BindingSourceId { get; set; } + public string DescriptorName { get; set; } + private ParameterApiDescriptionModel() { } - public static ParameterApiDescriptionModel Create(string name, string nameOnMethod, Type type, bool isOptional = false, object defaultValue = null, string[] constraintTypes = null, string bindingSourceId = null) + public static ParameterApiDescriptionModel Create(string name, string nameOnMethod, Type type, bool isOptional = false, object defaultValue = null, string[] constraintTypes = null, string bindingSourceId = null, string descriptorName = null) { return new ParameterApiDescriptionModel { @@ -34,7 +36,8 @@ namespace Volo.Abp.Http.Modeling IsOptional = isOptional, DefaultValue = defaultValue, ConstraintTypes = constraintTypes, - BindingSourceId = bindingSourceId + BindingSourceId = bindingSourceId, + DescriptorName = descriptorName }; } } diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs index 169e9b8764..b267c26296 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/JQuery/JQueryProxyScriptGenerator.cs @@ -96,7 +96,11 @@ namespace Volo.Abp.Http.ProxyScripting.Generators.JQuery AddAjaxCallParameters(script, action); - script.AppendLine(" }, ajaxParams));;"); + var ajaxParamsIsFromForm = action.Parameters.Any(x => x.BindingSourceId == ParameterBindingSources.Form); + script.AppendLine(ajaxParamsIsFromForm + ? " }, $.extend(true, {}, ajaxParams, { contentType: 'application/x-www-form-urlencoded; charset=UTF-8' })));" + : " }, ajaxParams));"); + script.AppendLine(" };"); } diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/ProxyScriptingHelper.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/ProxyScriptingHelper.cs index 64d1515574..700dc4e290 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/ProxyScriptingHelper.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/ProxyScriptingHelper.cs @@ -66,7 +66,7 @@ namespace Volo.Abp.Http.ProxyScripting.Generators return null; } - return ProxyScriptingJsFuncHelper.CreateJsObjectLiteral(parameters, indent); + return ProxyScriptingJsFuncHelper.CreateJsFormPostData(parameters, indent); } private static string ReplacePathVariables(string url, IList actionParameters) diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/ProxyScriptingJsFuncHelper.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/ProxyScriptingJsFuncHelper.cs index baa52f3155..0fd80203df 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/ProxyScriptingJsFuncHelper.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/ProxyScripting/Generators/ProxyScriptingJsFuncHelper.cs @@ -111,8 +111,8 @@ namespace Volo.Abp.Http.ProxyScripting.Generators public static string GetParamNameInJsFunc(ParameterApiDescriptionModel parameterInfo) { return parameterInfo.Name == parameterInfo.NameOnMethod - ? NormalizeJsVariableName(parameterInfo.Name.ToCamelCase(), ".") - : NormalizeJsVariableName(parameterInfo.NameOnMethod.ToCamelCase()) + "." + NormalizeJsVariableName(parameterInfo.Name.ToCamelCase(), "."); + ? NormalizeJsVariableName(parameterInfo.Name.ToCamelCase(), ".") + : NormalizeJsVariableName(parameterInfo.NameOnMethod.ToCamelCase()) + "." + NormalizeJsVariableName(parameterInfo.Name.ToCamelCase(), "."); } public static string CreateJsObjectLiteral(ParameterApiDescriptionModel[] parameters, int indent = 0) @@ -131,9 +131,37 @@ namespace Volo.Abp.Http.ProxyScripting.Generators return sb.ToString(); } + public static string GetFormPostParamNameInJsFunc(ParameterApiDescriptionModel parameterInfo) + { + return parameterInfo.Name == parameterInfo.NameOnMethod + ? NormalizeJsVariableName((parameterInfo.DescriptorName + parameterInfo.Name).ToCamelCase(), ".") + : NormalizeJsVariableName(parameterInfo.NameOnMethod.ToCamelCase()) + "." + NormalizeJsVariableName((parameterInfo.DescriptorName + parameterInfo.Name).ToCamelCase(), "."); + } + + public static string CreateJsFormPostData(ParameterApiDescriptionModel[] parameters, int indent) + { + var sb = new StringBuilder(); + + for (var i = 0; i < parameters.Length; i++) + { + var and = i < parameters.Length - 1 ? " + '&' + " : string.Empty; + + var parameterName = parameters[i].DescriptorName.IsNullOrWhiteSpace() + ? parameters[i].Name + : $"{parameters[i].DescriptorName}.{parameters[i].Name}"; + + sb.Append($"'{parameterName}=' + {GetFormPostParamNameInJsFunc(parameters[i])}{and}"); + } + + return sb.ToString(); + } + public static string GenerateJsFuncParameterList(ActionApiDescriptionModel action, string ajaxParametersName) { - var methodParamNames = action.ParametersOnMethod.Select(p => p.Name).Distinct().ToList(); + var paramsIsFromForm = action.Parameters.Any(x => x.BindingSourceId == ParameterBindingSources.Form); + var methodParamNames = paramsIsFromForm + ? action.Parameters.Select(p => p.DescriptorName + p.Name).Distinct().ToList() + : action.ParametersOnMethod.Select(p => p.Name).Distinct().ToList(); methodParamNames.Add(ajaxParametersName); return methodParamNames.Select(prmName => NormalizeJsVariableName(prmName.ToCamelCase())).JoinAsString(", "); } diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json index ea2d94f5f2..7cf2cf7be6 100644 --- a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json @@ -11,6 +11,7 @@ "InvalidUserNameOrPassword": "Invalid username or password!", "LoginIsNotAllowed": "You are not allowed to login! You need to confirm your email/phone number.", "SelfRegistrationDisabledMessage": "Self-registration is disabled for this application. Please contact the application administrator to register a new user.", + "LocalLoginDisabledMessage": "Local login is disabled for this application.", "Login": "Login", "Cancel": "Cancel", "Register": "Register", diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json index c778a28dd6..c02ff8669b 100644 --- a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json @@ -11,6 +11,7 @@ "InvalidUserNameOrPassword": "用户名或密码错误!", "LoginIsNotAllowed": "无法登录!你需要验证邮箱地址/手机号.", "SelfRegistrationDisabledMessage": "应用程序未开放注册,请联系管理员添加新用户.", + "LocalLoginDisabledMessage": "应用程序未开放本地账户登录.", "Login": "登录", "Cancel": "取消", "Register": "注册", diff --git a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hant.json b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hant.json index e21631e92e..b75be0f73a 100644 --- a/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hant.json +++ b/modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hant.json @@ -11,6 +11,7 @@ "InvalidUserNameOrPassword": "使用者名稱或密碼錯誤!", "LoginIsNotAllowed": "無法登入!你需要驗證電子信箱地址/手機號碼.", "SelfRegistrationDisabledMessage": "應用程式未開放註冊,請聯絡管理員以加入新使用者.", + "LocalLoginDisabledMessage": "應用程序未開放本地賬戶登錄.", "Login": "登入", "Cancel": "取消", "Register": "註冊", diff --git a/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs index 62bcb2eb3d..695d9b233f 100644 --- a/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs +++ b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Linq; +using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using Volo.Abp.Account.Settings; using Volo.Abp.Application.Services; @@ -9,11 +10,14 @@ namespace Volo.Abp.Account { public class AccountAppService : ApplicationService, IAccountAppService { + private readonly IIdentityRoleRepository _roleRepository; protected IdentityUserManager UserManager { get; } public AccountAppService( - IdentityUserManager userManager) + IdentityUserManager userManager, + IIdentityRoleRepository roleRepository) { + _roleRepository = roleRepository; UserManager = userManager; } @@ -25,9 +29,20 @@ namespace Volo.Abp.Account (await UserManager.CreateAsync(user, input.Password)).CheckErrors(); + await UserManager.SetEmailAsync(user,input.EmailAddress).ConfigureAwait(false); + + await SetDefaultRolesAsync(user); + return ObjectMapper.Map(user); } + protected virtual async Task SetDefaultRolesAsync(IdentityUser user) + { + var defaultRoles = await _roleRepository.GetDefaultOnesAsync().ConfigureAwait(false); + + await UserManager.SetRolesAsync(user, defaultRoles.Select(r => r.Name)).ConfigureAwait(false); + } + protected virtual async Task CheckSelfRegistrationAsync() { if (!await SettingProvider.IsTrueAsync(AccountSettingNames.IsSelfRegistrationEnabled)) diff --git a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs index 218baa7c60..c2e50a2317 100644 --- a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs +++ b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs @@ -107,8 +107,6 @@ namespace Volo.Abp.Account.Web.Pages.Account [UnitOfWork] //TODO: Will be removed when we implement action filter public override async Task OnPostAsync(string action) { - EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin); - if (action == "Cancel") { var context = await Interaction.GetAuthorizationContextAsync(ReturnUrl); @@ -122,6 +120,8 @@ namespace Volo.Abp.Account.Web.Pages.Account return Redirect(ReturnUrl); } + await CheckLocalLoginAsync(); + ValidateModel(); await ReplaceEmailToUsernameOfInputIfNeeds(); diff --git a/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs b/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs index 47702c6ca6..48b8da5c38 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs @@ -1,10 +1,13 @@ -using System; +using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; +using Volo.Abp.Account.Localization; +using Volo.Abp.Account.Settings; using Volo.Abp.Account.Web.Areas.Account.Controllers.Models; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.Identity; +using Volo.Abp.Settings; using Volo.Abp.Validation; using SignInResult = Microsoft.AspNetCore.Identity.SignInResult; using UserLoginInfo = Volo.Abp.Account.Web.Areas.Account.Controllers.Models.UserLoginInfo; @@ -21,17 +24,23 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers { private readonly SignInManager _signInManager; private readonly IdentityUserManager _userManager; + private readonly ISettingProvider _settingProvider; - public AccountController(SignInManager signInManager, IdentityUserManager userManager) + public AccountController(SignInManager signInManager, IdentityUserManager userManager, ISettingProvider settingProvider) { + LocalizationResource = typeof(AccountResource); + _signInManager = signInManager; _userManager = userManager; + _settingProvider = settingProvider; } [HttpPost] [Route("login")] public virtual async Task Login(UserLoginInfo login) { + await CheckLocalLoginAsync(); + ValidateLoginInfo(login); await ReplaceEmailToUsernameOfInputIfNeeds(login); @@ -133,5 +142,13 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers throw new ArgumentNullException(nameof(login.Password)); } } + + private async Task CheckLocalLoginAsync() + { + if (!await _settingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin).ConfigureAwait(false)) + { + throw new UserFriendlyException(L["LocalLoginDisabledMessage"]); + } + } } } diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs index dbcfd77499..a17a230f27 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs @@ -89,7 +89,7 @@ namespace Volo.Abp.Account.Web.Pages.Account [UnitOfWork] //TODO: Will be removed when we implement action filter public virtual async Task OnPostAsync(string action) { - EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin); + await CheckLocalLoginAsync(); ValidateModel(); @@ -237,6 +237,14 @@ namespace Volo.Abp.Account.Web.Pages.Account LoginInput.UserNameOrEmailAddress = userByEmail.UserName; } + protected virtual async Task CheckLocalLoginAsync() + { + if (!await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin).ConfigureAwait(false)) + { + throw new UserFriendlyException(L["LocalLoginDisabledMessage"]); + } + } + public class LoginInputModel { [Required] diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs index cf9cd7306c..16228ce601 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs @@ -1,8 +1,10 @@ using System.ComponentModel.DataAnnotations; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Volo.Abp.Account.Settings; +using Volo.Abp.Application.Dtos; using Volo.Abp.Identity; using Volo.Abp.Settings; using Volo.Abp.Uow; @@ -12,6 +14,8 @@ namespace Volo.Abp.Account.Web.Pages.Account { public class RegisterModel : AccountPageModel { + private readonly IAccountAppService _accountAppService; + [BindProperty(SupportsGet = true)] public string ReturnUrl { get; set; } @@ -21,7 +25,12 @@ namespace Volo.Abp.Account.Web.Pages.Account [BindProperty] public PostInput Input { get; set; } - public virtual async Task OnGet() + public RegisterModel(IAccountAppService accountAppService) + { + _accountAppService = accountAppService; + } + + public virtual async Task OnGetAsync() { await CheckSelfRegistrationAsync(); } @@ -33,9 +42,16 @@ namespace Volo.Abp.Account.Web.Pages.Account await CheckSelfRegistrationAsync(); - var user = new IdentityUser(GuidGenerator.Create(), Input.UserName, Input.EmailAddress, CurrentTenant.Id); + var registerDto = new RegisterDto + { + AppName = "MVC", + EmailAddress = Input.EmailAddress, + Password = Input.Password, + UserName = Input.UserName + }; - (await UserManager.CreateAsync(user, Input.Password)).CheckErrors(); + var userDto = await _accountAppService.RegisterAsync(registerDto); + var user = await UserManager.GetByIdAsync(userDto.Id); await UserManager.SetEmailAsync(user, Input.EmailAddress); diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs index 6ce3ce3c0c..3a344b3140 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs @@ -21,5 +21,10 @@ namespace Volo.Abp.Identity bool includeDetails = false, CancellationToken cancellationToken = default ); + + Task> GetDefaultOnesAsync( + bool includeDetails = false, + CancellationToken cancellationToken = default + ); } } \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs index a9850164ef..dfaaf51d91 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs @@ -42,6 +42,12 @@ namespace Volo.Abp.Identity.EntityFrameworkCore .ToListAsync(GetCancellationToken(cancellationToken)); } + public virtual async Task> GetDefaultOnesAsync( + bool includeDetails = false, CancellationToken cancellationToken = default) + { + return await DbSet.IncludeDetails(includeDetails).Where(r => r.IsDefault).ToListAsync(GetCancellationToken(cancellationToken)); + } + public override IQueryable WithDetails() { return GetQueryable().IncludeDetails(); diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs index 50c1403a03..10f77836c9 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs @@ -43,5 +43,11 @@ namespace Volo.Abp.Identity.MongoDB .PageBy>(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } + + public virtual async Task> GetDefaultOnesAsync( + bool includeDetails = false, CancellationToken cancellationToken = default) + { + return await GetMongoQueryable().Where(r => r.IsDefault).ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); + } } } \ No newline at end of file diff --git a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityRoleRepository_Tests.cs b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityRoleRepository_Tests.cs index e4a15d15f1..eb22de0600 100644 --- a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityRoleRepository_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityRoleRepository_Tests.cs @@ -36,6 +36,17 @@ namespace Volo.Abp.Identity roles.ShouldContain(r => r.Name == "supporter"); } + [Fact] + public async Task GetDefaultOnesAsync() + { + var roles = await RoleRepository.GetDefaultOnesAsync().ConfigureAwait(false); + + foreach (var role in roles) + { + role.IsDefault.ShouldBe(true); + } + } + [Fact] public async Task GetCountAsync() { diff --git a/samples/BasicConsoleApplication/AbpConsoleDemo/AbpConsoleDemo.csproj b/samples/BasicConsoleApplication/AbpConsoleDemo/AbpConsoleDemo.csproj index 1eb6949649..9e20015c9f 100644 --- a/samples/BasicConsoleApplication/AbpConsoleDemo/AbpConsoleDemo.csproj +++ b/samples/BasicConsoleApplication/AbpConsoleDemo/AbpConsoleDemo.csproj @@ -7,6 +7,7 @@ + diff --git a/samples/BasicConsoleApplication/AbpConsoleDemo/AppHostedService.cs b/samples/BasicConsoleApplication/AbpConsoleDemo/AppHostedService.cs new file mode 100644 index 0000000000..578c437177 --- /dev/null +++ b/samples/BasicConsoleApplication/AbpConsoleDemo/AppHostedService.cs @@ -0,0 +1,32 @@ +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Volo.Abp; + +namespace AbpConsoleDemo +{ + public class AppHostedService : IHostedService + { + public Task StartAsync(CancellationToken cancellationToken) + { + using (var application = AbpApplicationFactory.Create(options => + { + options.UseAutofac(); //Autofac integration + })) + { + application.Initialize(); + + //Resolve a service and use it + var helloWorldService = application.ServiceProvider.GetService(); + helloWorldService.SayHello(); + + application.Shutdown(); + } + + return Task.CompletedTask; + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + } +} diff --git a/samples/BasicConsoleApplication/AbpConsoleDemo/Program.cs b/samples/BasicConsoleApplication/AbpConsoleDemo/Program.cs index 651fda3c4f..2c8791f656 100644 --- a/samples/BasicConsoleApplication/AbpConsoleDemo/Program.cs +++ b/samples/BasicConsoleApplication/AbpConsoleDemo/Program.cs @@ -1,28 +1,21 @@ -using System; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Volo.Abp; +using Microsoft.Extensions.Hosting; namespace AbpConsoleDemo { class Program { - static void Main(string[] args) + static async Task Main(string[] args) { - using (var application = AbpApplicationFactory.Create(options => - { - options.UseAutofac(); //Autofac integration - })) - { - application.Initialize(); - - //Resolve a service and use it - var helloWorldService = - application.ServiceProvider.GetService(); - helloWorldService.SayHello(); - - Console.WriteLine("Press ENTER to stop application..."); - Console.ReadLine(); - } + await CreateHostBuilder(args).RunConsoleAsync(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + }); } } diff --git a/samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.DbMigrator/DbMigratorHostedService.cs b/samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.DbMigrator/DbMigratorHostedService.cs new file mode 100644 index 0000000000..aef3d88bb5 --- /dev/null +++ b/samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.DbMigrator/DbMigratorHostedService.cs @@ -0,0 +1,34 @@ +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Acme.BookStore.Data; +using Serilog; +using Volo.Abp; + +namespace Acme.BookStore.DbMigrator +{ + public class DbMigratorHostedService : IHostedService + { + public async Task StartAsync(CancellationToken cancellationToken) + { + using (var application = AbpApplicationFactory.Create(options => + { + options.UseAutofac(); + options.Services.AddLogging(c => c.AddSerilog()); + })) + { + application.Initialize(); + + await application + .ServiceProvider + .GetRequiredService() + .MigrateAsync(); + + application.Shutdown(); + } + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + } +} diff --git a/samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.DbMigrator/Program.cs b/samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.DbMigrator/Program.cs index d3c4034c8a..179c18f4ca 100644 --- a/samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.DbMigrator/Program.cs +++ b/samples/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.DbMigrator/Program.cs @@ -1,39 +1,15 @@ -using System.IO; +using System.IO; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Acme.BookStore.Data; +using Microsoft.Extensions.Hosting; using Serilog; using Serilog.Events; -using Volo.Abp; -using Volo.Abp.Threading; namespace Acme.BookStore.DbMigrator { class Program { - static void Main(string[] args) - { - ConfigureLogging(); - - using (var application = AbpApplicationFactory.Create(options => - { - options.UseAutofac(); - options.Services.AddLogging(c => c.AddSerilog()); - })) - { - application.Initialize(); - - AsyncHelper.RunSync( - () => application - .ServiceProvider - .GetRequiredService() - .MigrateAsync() - ); - - application.Shutdown(); - } - } - - private static void ConfigureLogging() + static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Information() @@ -48,6 +24,15 @@ namespace Acme.BookStore.DbMigrator .WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "Logs/logs.txt")) .WriteTo.Console() .CreateLogger(); + + await CreateHostBuilder(args).RunConsoleAsync(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + }); } } diff --git a/samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs b/samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs new file mode 100644 index 0000000000..e41ee7ed31 --- /dev/null +++ b/samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs @@ -0,0 +1,26 @@ +using Microsoft.Extensions.Hosting; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; + +namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp +{ + public class ConsoleTestAppHostedService : IHostedService + { + public async Task StartAsync(CancellationToken cancellationToken) + { + using (var application = AbpApplicationFactory.Create()) + { + application.Initialize(); + + var demo = application.ServiceProvider.GetRequiredService(); + await demo.RunAsync(); + + application.Shutdown(); + } + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + } +} diff --git a/samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs b/samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs index ecef29d963..7d8265158b 100644 --- a/samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs +++ b/samples/BookStore-Angular-MongoDb/aspnet-core/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs @@ -1,24 +1,21 @@ -using System; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Volo.Abp; -using Volo.Abp.Threading; +using Microsoft.Extensions.Hosting; namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp { class Program { - static void Main(string[] args) + static async Task Main(string[] args) { - using (var application = AbpApplicationFactory.Create()) - { - application.Initialize(); - - var demo = application.ServiceProvider.GetRequiredService(); - AsyncHelper.RunSync(() => demo.RunAsync()); - - Console.WriteLine("Press ENTER to stop application..."); - Console.ReadLine(); - } + await CreateHostBuilder(args).RunConsoleAsync(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + }); } } diff --git a/samples/BookStore-Modular/application/src/Acme.BookStore.DbMigrator/DbMigratorHostedService.cs b/samples/BookStore-Modular/application/src/Acme.BookStore.DbMigrator/DbMigratorHostedService.cs new file mode 100644 index 0000000000..aef3d88bb5 --- /dev/null +++ b/samples/BookStore-Modular/application/src/Acme.BookStore.DbMigrator/DbMigratorHostedService.cs @@ -0,0 +1,34 @@ +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Acme.BookStore.Data; +using Serilog; +using Volo.Abp; + +namespace Acme.BookStore.DbMigrator +{ + public class DbMigratorHostedService : IHostedService + { + public async Task StartAsync(CancellationToken cancellationToken) + { + using (var application = AbpApplicationFactory.Create(options => + { + options.UseAutofac(); + options.Services.AddLogging(c => c.AddSerilog()); + })) + { + application.Initialize(); + + await application + .ServiceProvider + .GetRequiredService() + .MigrateAsync(); + + application.Shutdown(); + } + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + } +} diff --git a/samples/BookStore-Modular/application/src/Acme.BookStore.DbMigrator/Program.cs b/samples/BookStore-Modular/application/src/Acme.BookStore.DbMigrator/Program.cs index d3c4034c8a..179c18f4ca 100644 --- a/samples/BookStore-Modular/application/src/Acme.BookStore.DbMigrator/Program.cs +++ b/samples/BookStore-Modular/application/src/Acme.BookStore.DbMigrator/Program.cs @@ -1,39 +1,15 @@ -using System.IO; +using System.IO; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Acme.BookStore.Data; +using Microsoft.Extensions.Hosting; using Serilog; using Serilog.Events; -using Volo.Abp; -using Volo.Abp.Threading; namespace Acme.BookStore.DbMigrator { class Program { - static void Main(string[] args) - { - ConfigureLogging(); - - using (var application = AbpApplicationFactory.Create(options => - { - options.UseAutofac(); - options.Services.AddLogging(c => c.AddSerilog()); - })) - { - application.Initialize(); - - AsyncHelper.RunSync( - () => application - .ServiceProvider - .GetRequiredService() - .MigrateAsync() - ); - - application.Shutdown(); - } - } - - private static void ConfigureLogging() + static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Information() @@ -48,6 +24,15 @@ namespace Acme.BookStore.DbMigrator .WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "Logs/logs.txt")) .WriteTo.Console() .CreateLogger(); + + await CreateHostBuilder(args).RunConsoleAsync(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + }); } } diff --git a/samples/BookStore-Modular/application/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs b/samples/BookStore-Modular/application/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs new file mode 100644 index 0000000000..e41ee7ed31 --- /dev/null +++ b/samples/BookStore-Modular/application/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs @@ -0,0 +1,26 @@ +using Microsoft.Extensions.Hosting; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; + +namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp +{ + public class ConsoleTestAppHostedService : IHostedService + { + public async Task StartAsync(CancellationToken cancellationToken) + { + using (var application = AbpApplicationFactory.Create()) + { + application.Initialize(); + + var demo = application.ServiceProvider.GetRequiredService(); + await demo.RunAsync(); + + application.Shutdown(); + } + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + } +} diff --git a/samples/BookStore-Modular/application/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs b/samples/BookStore-Modular/application/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs index ecef29d963..7d8265158b 100644 --- a/samples/BookStore-Modular/application/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs +++ b/samples/BookStore-Modular/application/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs @@ -1,24 +1,21 @@ -using System; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Volo.Abp; -using Volo.Abp.Threading; +using Microsoft.Extensions.Hosting; namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp { class Program { - static void Main(string[] args) + static async Task Main(string[] args) { - using (var application = AbpApplicationFactory.Create()) - { - application.Initialize(); - - var demo = application.ServiceProvider.GetRequiredService(); - AsyncHelper.RunSync(() => demo.RunAsync()); - - Console.WriteLine("Press ENTER to stop application..."); - Console.ReadLine(); - } + await CreateHostBuilder(args).RunConsoleAsync(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + }); } } diff --git a/samples/BookStore-Modular/modules/book-management/test/Acme.BookStore.BookManagement.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs b/samples/BookStore-Modular/modules/book-management/test/Acme.BookStore.BookManagement.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs new file mode 100644 index 0000000000..aec5d0252d --- /dev/null +++ b/samples/BookStore-Modular/modules/book-management/test/Acme.BookStore.BookManagement.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs @@ -0,0 +1,26 @@ +using Microsoft.Extensions.Hosting; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; + +namespace Acme.BookStore.BookManagement +{ + public class ConsoleTestAppHostedService : IHostedService + { + public async Task StartAsync(CancellationToken cancellationToken) + { + using (var application = AbpApplicationFactory.Create()) + { + application.Initialize(); + + var demo = application.ServiceProvider.GetRequiredService(); + await demo.RunAsync(); + + application.Shutdown(); + } + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + } +} diff --git a/samples/BookStore-Modular/modules/book-management/test/Acme.BookStore.BookManagement.HttpApi.Client.ConsoleTestApp/Program.cs b/samples/BookStore-Modular/modules/book-management/test/Acme.BookStore.BookManagement.HttpApi.Client.ConsoleTestApp/Program.cs index 9b6e256930..f69d97f590 100644 --- a/samples/BookStore-Modular/modules/book-management/test/Acme.BookStore.BookManagement.HttpApi.Client.ConsoleTestApp/Program.cs +++ b/samples/BookStore-Modular/modules/book-management/test/Acme.BookStore.BookManagement.HttpApi.Client.ConsoleTestApp/Program.cs @@ -1,24 +1,21 @@ -using System; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Volo.Abp; -using Volo.Abp.Threading; +using Microsoft.Extensions.Hosting; namespace Acme.BookStore.BookManagement { class Program { - static void Main(string[] args) + static async Task Main(string[] args) { - using (var application = AbpApplicationFactory.Create()) - { - application.Initialize(); - - var demo = application.ServiceProvider.GetRequiredService(); - AsyncHelper.RunSync(() => demo.RunAsync()); - - Console.WriteLine("Press ENTER to stop application..."); - Console.ReadLine(); - } + await CreateHostBuilder(args).RunConsoleAsync(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + }); } } diff --git a/samples/BookStore/src/Acme.BookStore.DbMigrator/DbMigratorHostedService.cs b/samples/BookStore/src/Acme.BookStore.DbMigrator/DbMigratorHostedService.cs new file mode 100644 index 0000000000..aef3d88bb5 --- /dev/null +++ b/samples/BookStore/src/Acme.BookStore.DbMigrator/DbMigratorHostedService.cs @@ -0,0 +1,34 @@ +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Acme.BookStore.Data; +using Serilog; +using Volo.Abp; + +namespace Acme.BookStore.DbMigrator +{ + public class DbMigratorHostedService : IHostedService + { + public async Task StartAsync(CancellationToken cancellationToken) + { + using (var application = AbpApplicationFactory.Create(options => + { + options.UseAutofac(); + options.Services.AddLogging(c => c.AddSerilog()); + })) + { + application.Initialize(); + + await application + .ServiceProvider + .GetRequiredService() + .MigrateAsync(); + + application.Shutdown(); + } + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + } +} diff --git a/samples/BookStore/src/Acme.BookStore.DbMigrator/Program.cs b/samples/BookStore/src/Acme.BookStore.DbMigrator/Program.cs index d3c4034c8a..179c18f4ca 100644 --- a/samples/BookStore/src/Acme.BookStore.DbMigrator/Program.cs +++ b/samples/BookStore/src/Acme.BookStore.DbMigrator/Program.cs @@ -1,39 +1,15 @@ -using System.IO; +using System.IO; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Acme.BookStore.Data; +using Microsoft.Extensions.Hosting; using Serilog; using Serilog.Events; -using Volo.Abp; -using Volo.Abp.Threading; namespace Acme.BookStore.DbMigrator { class Program { - static void Main(string[] args) - { - ConfigureLogging(); - - using (var application = AbpApplicationFactory.Create(options => - { - options.UseAutofac(); - options.Services.AddLogging(c => c.AddSerilog()); - })) - { - application.Initialize(); - - AsyncHelper.RunSync( - () => application - .ServiceProvider - .GetRequiredService() - .MigrateAsync() - ); - - application.Shutdown(); - } - } - - private static void ConfigureLogging() + static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Information() @@ -48,6 +24,15 @@ namespace Acme.BookStore.DbMigrator .WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "Logs/logs.txt")) .WriteTo.Console() .CreateLogger(); + + await CreateHostBuilder(args).RunConsoleAsync(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + }); } } diff --git a/samples/BookStore/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs b/samples/BookStore/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs new file mode 100644 index 0000000000..e41ee7ed31 --- /dev/null +++ b/samples/BookStore/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs @@ -0,0 +1,26 @@ +using Microsoft.Extensions.Hosting; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; + +namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp +{ + public class ConsoleTestAppHostedService : IHostedService + { + public async Task StartAsync(CancellationToken cancellationToken) + { + using (var application = AbpApplicationFactory.Create()) + { + application.Initialize(); + + var demo = application.ServiceProvider.GetRequiredService(); + await demo.RunAsync(); + + application.Shutdown(); + } + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + } +} diff --git a/samples/BookStore/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs b/samples/BookStore/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs index ecef29d963..7d8265158b 100644 --- a/samples/BookStore/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs +++ b/samples/BookStore/test/Acme.BookStore.HttpApi.Client.ConsoleTestApp/Program.cs @@ -1,24 +1,21 @@ -using System; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Volo.Abp; -using Volo.Abp.Threading; +using Microsoft.Extensions.Hosting; namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp { class Program { - static void Main(string[] args) + static async Task Main(string[] args) { - using (var application = AbpApplicationFactory.Create()) - { - application.Initialize(); - - var demo = application.ServiceProvider.GetRequiredService(); - AsyncHelper.RunSync(() => demo.RunAsync()); - - Console.WriteLine("Press ENTER to stop application..."); - Console.ReadLine(); - } + await CreateHostBuilder(args).RunConsoleAsync(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + }); } } diff --git a/samples/DashboardDemo/src/DashboardDemo.DbMigrator/DbMigratorHostedService.cs b/samples/DashboardDemo/src/DashboardDemo.DbMigrator/DbMigratorHostedService.cs new file mode 100644 index 0000000000..dcfd612adc --- /dev/null +++ b/samples/DashboardDemo/src/DashboardDemo.DbMigrator/DbMigratorHostedService.cs @@ -0,0 +1,34 @@ +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using DashboardDemo.Data; +using Serilog; +using Volo.Abp; + +namespace DashboardDemo.DbMigrator +{ + public class DbMigratorHostedService : IHostedService + { + public async Task StartAsync(CancellationToken cancellationToken) + { + using (var application = AbpApplicationFactory.Create(options => + { + options.UseAutofac(); + options.Services.AddLogging(c => c.AddSerilog()); + })) + { + application.Initialize(); + + await application + .ServiceProvider + .GetRequiredService() + .MigrateAsync(); + + application.Shutdown(); + } + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + } +} diff --git a/samples/DashboardDemo/src/DashboardDemo.DbMigrator/Program.cs b/samples/DashboardDemo/src/DashboardDemo.DbMigrator/Program.cs index 3cfe1b680a..ccfa70ea32 100644 --- a/samples/DashboardDemo/src/DashboardDemo.DbMigrator/Program.cs +++ b/samples/DashboardDemo/src/DashboardDemo.DbMigrator/Program.cs @@ -1,39 +1,15 @@ -using System.IO; +using System.IO; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using DashboardDemo.Data; +using Microsoft.Extensions.Hosting; using Serilog; using Serilog.Events; -using Volo.Abp; -using Volo.Abp.Threading; namespace DashboardDemo.DbMigrator { class Program { - static void Main(string[] args) - { - ConfigureLogging(); - - using (var application = AbpApplicationFactory.Create(options => - { - options.UseAutofac(); - options.Services.AddLogging(c => c.AddSerilog()); - })) - { - application.Initialize(); - - AsyncHelper.RunSync( - () => application - .ServiceProvider - .GetRequiredService() - .MigrateAsync() - ); - - application.Shutdown(); - } - } - - private static void ConfigureLogging() + static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Information() @@ -48,6 +24,15 @@ namespace DashboardDemo.DbMigrator .WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "Logs/logs.txt")) .WriteTo.Console() .CreateLogger(); + + await CreateHostBuilder(args).RunConsoleAsync(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + }); } } diff --git a/samples/DashboardDemo/test/DashboardDemo.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs b/samples/DashboardDemo/test/DashboardDemo.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs new file mode 100644 index 0000000000..b10baf1daa --- /dev/null +++ b/samples/DashboardDemo/test/DashboardDemo.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs @@ -0,0 +1,26 @@ +using Microsoft.Extensions.Hosting; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; + +namespace DashboardDemo.HttpApi.Client.ConsoleTestApp +{ + public class ConsoleTestAppHostedService : IHostedService + { + public async Task StartAsync(CancellationToken cancellationToken) + { + using (var application = AbpApplicationFactory.Create()) + { + application.Initialize(); + + var demo = application.ServiceProvider.GetRequiredService(); + await demo.RunAsync(); + + application.Shutdown(); + } + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + } +} diff --git a/samples/DashboardDemo/test/DashboardDemo.HttpApi.Client.ConsoleTestApp/Program.cs b/samples/DashboardDemo/test/DashboardDemo.HttpApi.Client.ConsoleTestApp/Program.cs index c48298d7d4..7ba0e8151e 100644 --- a/samples/DashboardDemo/test/DashboardDemo.HttpApi.Client.ConsoleTestApp/Program.cs +++ b/samples/DashboardDemo/test/DashboardDemo.HttpApi.Client.ConsoleTestApp/Program.cs @@ -1,24 +1,21 @@ -using System; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Volo.Abp; -using Volo.Abp.Threading; +using Microsoft.Extensions.Hosting; namespace DashboardDemo.HttpApi.Client.ConsoleTestApp { class Program { - static void Main(string[] args) + static async Task Main(string[] args) { - using (var application = AbpApplicationFactory.Create()) - { - application.Initialize(); - - var demo = application.ServiceProvider.GetRequiredService(); - AsyncHelper.RunSync(() => demo.RunAsync()); - - Console.WriteLine("Press ENTER to stop application..."); - Console.ReadLine(); - } + await CreateHostBuilder(args).RunConsoleAsync(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + }); } } diff --git a/samples/MicroserviceDemo/applications/ConsoleClientDemo/ConsoleClientDemoHostedService.cs b/samples/MicroserviceDemo/applications/ConsoleClientDemo/ConsoleClientDemoHostedService.cs new file mode 100644 index 0000000000..e07c8564eb --- /dev/null +++ b/samples/MicroserviceDemo/applications/ConsoleClientDemo/ConsoleClientDemoHostedService.cs @@ -0,0 +1,33 @@ +using Microsoft.Extensions.Hosting; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Serilog; + +namespace ConsoleClientDemo +{ + public class ConsoleClientDemoHostedService : IHostedService + { + public async Task StartAsync(CancellationToken cancellationToken) + { + using (var application = AbpApplicationFactory.Create(options => + { + options.Services.AddLogging(loggingBuilder => + { + loggingBuilder.AddSerilog(dispose: true); + }); + })) + { + application.Initialize(); + + var demo = application.ServiceProvider.GetRequiredService(); + await demo.RunAsync(); + + application.Shutdown(); + } + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + } +} diff --git a/samples/MicroserviceDemo/applications/ConsoleClientDemo/Program.cs b/samples/MicroserviceDemo/applications/ConsoleClientDemo/Program.cs index 9626e874a1..40082b1d2a 100644 --- a/samples/MicroserviceDemo/applications/ConsoleClientDemo/Program.cs +++ b/samples/MicroserviceDemo/applications/ConsoleClientDemo/Program.cs @@ -1,48 +1,14 @@ -using Serilog; -using Serilog.Events; -using System; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Volo.Abp; -using Volo.Abp.Threading; +using Microsoft.Extensions.Hosting; +using Serilog; +using Serilog.Events; namespace ConsoleClientDemo { internal class Program { - private static void Main(string[] args) - { - InitializeSerilog(); - - Log.Information("Starting ConsoleClientDemo..."); - - try - { - using (var application = AbpApplicationFactory.Create(options => - { - options.Services.AddLogging(loggingBuilder => - { - loggingBuilder.AddSerilog(dispose: true); - }); - })) - { - application.Initialize(); - - var demo = application.ServiceProvider.GetRequiredService(); - AsyncHelper.RunSync(() => demo.RunAsync()); - - Console.WriteLine("Press ENTER to stop application..."); - Console.ReadLine(); - } - } - catch (Exception ex) - { - Log.Error(ex.Message); - Log.Error(ex.StackTrace); - throw; - } - } - - private static void InitializeSerilog() + static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() @@ -50,6 +16,17 @@ namespace ConsoleClientDemo .Enrich.FromLogContext() .WriteTo.File("Logs/logs.txt") .CreateLogger(); + + Log.Information("Starting ConsoleClientDemo..."); + + await CreateHostBuilder(args).RunConsoleAsync(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + }); } } diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/DbMigratorHostedService.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/DbMigratorHostedService.cs new file mode 100644 index 0000000000..730a7f7369 --- /dev/null +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/DbMigratorHostedService.cs @@ -0,0 +1,34 @@ +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using MyCompanyName.MyProjectName.Data; +using Serilog; +using Volo.Abp; + +namespace MyCompanyName.MyProjectName.DbMigrator +{ + public class DbMigratorHostedService : IHostedService + { + public async Task StartAsync(CancellationToken cancellationToken) + { + using (var application = AbpApplicationFactory.Create(options => + { + options.UseAutofac(); + options.Services.AddLogging(c => c.AddSerilog()); + })) + { + application.Initialize(); + + await application + .ServiceProvider + .GetRequiredService() + .MigrateAsync(); + + application.Shutdown(); + } + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + } +} diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/Program.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/Program.cs index 1a9175bbee..d1556ea371 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/Program.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/Program.cs @@ -1,39 +1,15 @@ -using System.IO; +using System.IO; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using MyCompanyName.MyProjectName.Data; +using Microsoft.Extensions.Hosting; using Serilog; using Serilog.Events; -using Volo.Abp; -using Volo.Abp.Threading; namespace MyCompanyName.MyProjectName.DbMigrator { class Program { - static void Main(string[] args) - { - ConfigureLogging(); - - using (var application = AbpApplicationFactory.Create(options => - { - options.UseAutofac(); - options.Services.AddLogging(c => c.AddSerilog()); - })) - { - application.Initialize(); - - AsyncHelper.RunSync( - () => application - .ServiceProvider - .GetRequiredService() - .MigrateAsync() - ); - - application.Shutdown(); - } - } - - private static void ConfigureLogging() + static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Information() @@ -48,6 +24,15 @@ namespace MyCompanyName.MyProjectName.DbMigrator .WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "Logs/logs.txt")) .WriteTo.Console() .CreateLogger(); + + await CreateHostBuilder(args).RunConsoleAsync(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + }); } } diff --git a/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs b/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs new file mode 100644 index 0000000000..ae929ced30 --- /dev/null +++ b/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs @@ -0,0 +1,26 @@ +using Microsoft.Extensions.Hosting; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; + +namespace MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp +{ + public class ConsoleTestAppHostedService : IHostedService + { + public async Task StartAsync(CancellationToken cancellationToken) + { + using (var application = AbpApplicationFactory.Create()) + { + application.Initialize(); + + var demo = application.ServiceProvider.GetRequiredService(); + await demo.RunAsync(); + + application.Shutdown(); + } + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + } +} diff --git a/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/Program.cs b/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/Program.cs index ada0212483..1e24d8a349 100644 --- a/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/Program.cs +++ b/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/Program.cs @@ -1,24 +1,21 @@ -using System; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Volo.Abp; -using Volo.Abp.Threading; +using Microsoft.Extensions.Hosting; namespace MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp { class Program { - static void Main(string[] args) + static async Task Main(string[] args) { - using (var application = AbpApplicationFactory.Create()) - { - application.Initialize(); - - var demo = application.ServiceProvider.GetRequiredService(); - AsyncHelper.RunSync(() => demo.RunAsync()); - - Console.WriteLine("Press ENTER to stop application..."); - Console.ReadLine(); - } + await CreateHostBuilder(args).RunConsoleAsync(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + }); } } diff --git a/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs b/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs new file mode 100644 index 0000000000..1ea99ce263 --- /dev/null +++ b/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/ConsoleTestAppHostedService.cs @@ -0,0 +1,26 @@ +using Microsoft.Extensions.Hosting; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; + +namespace MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp +{ + public class ConsoleTestAppHostedService : IHostedService + { + public async Task StartAsync(CancellationToken cancellationToken) + { + using (var application = AbpApplicationFactory.Create()) + { + application.Initialize(); + + var demo = application.ServiceProvider.GetRequiredService(); + await demo.RunAsync(); + + application.Shutdown(); + } + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + } +} diff --git a/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/Program.cs b/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/Program.cs index 23192c4e92..1e24d8a349 100644 --- a/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/Program.cs +++ b/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/Program.cs @@ -1,24 +1,21 @@ -using System; +using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Volo.Abp; -using Volo.Abp.Threading; +using Microsoft.Extensions.Hosting; -namespace MyCompanyName.MyProjectName +namespace MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp { class Program { - static void Main(string[] args) + static async Task Main(string[] args) { - using (var application = AbpApplicationFactory.Create()) - { - application.Initialize(); - - var demo = application.ServiceProvider.GetRequiredService(); - AsyncHelper.RunSync(() => demo.RunAsync()); - - Console.WriteLine("Press ENTER to stop application..."); - Console.ReadLine(); - } + await CreateHostBuilder(args).RunConsoleAsync(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + }); } }