ABP-Samples学习笔记
Posted *Hunter
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABP-Samples学习笔记相关的知识,希望对你有一定的参考价值。
using System; using Abp; using Abp.Dependency; using Castle.Facilities.Logging; namespace AbpEfConsoleApp { public class Program { static void Main(string[] args) { //引导ABP系统 using (var bootstrapper = AbpBootstrapper.Create<MyConsoleAppModule>()) { bootstrapper.IocManager .IocContainer .AddFacility<LoggingFacility>(f => f.UseLog4Net().WithConfig("log4net.config")); bootstrapper.Initialize(); //从DI获取测试对象并运行它 using (var tester = bootstrapper.IocManager.ResolveAsDisposable<Tester>()) { tester.Object.Run(); } //部署测试和所有它的依赖 Console.WriteLine("Press enter to exit..."); Console.ReadLine(); } } } }
using System.Reflection; using Abp.EntityFramework; using Abp.Modules; namespace AbpEfConsoleApp { //定义模块取决于AbpEntityFrameworkModule [DependsOn(typeof(AbpEntityFrameworkModule))] public class MyConsoleAppModule : AbpModule { public override void Initialize() { IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly()); } } }
using System.Reflection; using Abp.Application.Services; using Abp.Modules; using Abp.WebApi; using Abp.WebApi.Controllers.Dynamic.Builders; using OtherApp.Application; namespace AbpSwagger.Application.WebApi.WebApi { [DependsOn( typeof(AbpWebApiModule), typeof(AbpSwaggerAppModule), typeof(OtherAppModule))] public class SwaggerWebApiModule : AbpModule { public override void Initialize() { IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly()); DynamicApiControllerBuilder .ForAll<IApplicationService>(typeof(AbpSwaggerAppModule).Assembly, "app") .WithConventionalVerbs() .Build(); DynamicApiControllerBuilder .ForAll<IApplicationService>(typeof(OtherAppModule).Assembly, "app") .Build(); } } }
//AES对称加密 SimpleStringCipher.Instance.Encrypt(input.ConnectionString)
//实现密码哈希方法 new PasswordHasher().HashPassword(input.Password)
DynamicApiControllerBuilder .ForAll<IApplicationService>(typeof(ChargeStationApplicationModule).Assembly, "ChargeStationAPI") .Build();//告诉生成器为所有实现了IApplicationService接口的服务方法创建api控制器 DynamicApiControllerBuilder .For<ICityAppService>("ChargeStationAPI/City") .ForMethod("CreateCity").DontCreateAction() .Build();//忽略"ChargeStationAPI/City"的"CreateCity"方法
①使用WithVerb
DynamicApiControllerBuilder.For<ICityAppService>("ChargeStationAPI/City") .ForMethod("getCities").WithVerb(HttpVerb.Get) .Build();
②使用特性(需要添加Microsoft.AspNet.WebApi.Core Nuget包的引用)
public interface ICityAppService:IApplicationService { [HttpGet] GetCitiesOutput GetCities(GetCityInput input); [HttpPost] void UpdateCity(CityInput input); }
③使用restful风格
DynamicApiControllerBuilder .ForAll<IApplicationService>(typeof(ChargeStationApplicationModule).Assembly, "ChargeStationAPI") .WithConventionalVerbs()//根据方法名使用惯例HTTP动词,默认对于所有的action使用Post .Build();
九十九、api用法
//_userManager.SetRoles方法的作用:变更角色(前提:用户表以已经创建) CheckErrors(await _userManager.SetRoles(user, input.RoleNames));
//admin用户不能被删除(删除用户的同时会删除UserRole) await _userManager.DeleteAsync(user);
用户名只能包含字母或数字
以上是关于ABP-Samples学习笔记的主要内容,如果未能解决你的问题,请参考以下文章
[原创]java WEB学习笔记61:Struts2学习之路--通用标签 property,uri,param,set,push,if-else,itertor,sort,date,a标签等(代码片段