/// <summary> /// 核心实现 /// </summary> /// <param name="application"></param> public void Apply(ApplicationModel application) { //这里已经拿到了所有的控制器信息,包括web层和service层的。要查看此前是怎么将service转成控制器的 AbpDebug.WriteLine($"全部的控制器信息:{application.Controllers.Select(c => c.ControllerName).JoinAsString(" \r\n ")}"); foreach (var controller in application.Controllers) { var tempName = controller.ControllerName; var type = controller.ControllerType.AsType(); var configuration = GetControllerSettingOrNull(type); //判断当前控制器是否由服务直接生成,是的话移除后缀。并生成相应的路径配置 if (typeof(IApplicationService).GetTypeInfo().IsAssignableFrom(type)) { //移除类名的后缀:"AppService", "ApplicationService" controller.ControllerName = controller.ControllerName.RemovePostFix(ApplicationService.CommonPostfixes); AbpDebug.WriteLine($"controller.ControllerName={controller.ControllerName},configuration.ModuleName:{configuration?.ModuleName}"); configuration?.ControllerModelConfigurer(controller); //把service生成的api模块配置成area,本身的控制器视图页已经有了area的路由配置,无需处理 ConfigureArea(controller, configuration); //配置web api ConfigureRemoteService(controller, configuration); } else { //如果是由控制器类实例得来的,判断是否有RemoteService标签。如果有,也要生成相应的 路径。 var remoteServiceAtt = ReflectionHelper.GetSingleAttributeOrDefault <RemoteServiceAttribute>(type.GetTypeInfo()); if (remoteServiceAtt != null && remoteServiceAtt.IsEnabledFor(type)) { ConfigureRemoteService(controller, configuration); } } } }
public override void OnActionExecuting(ActionExecutingContext context) { AbpDebug.WriteLine($"执行了{nameof(SurroundClassActionFilterAttribute)},{nameof(OnActionExecuting)},{_name}"); context.HttpContext.Response.Headers.Add(_name, new[] { _name }); base.OnActionExecuting(context); }
public static void SetCreationAuditProperties( IMultiTenancyConfig multiTenancyConfig, object entityAsObj, int?tenantId, long?userId) { var entityWithCreationTime = entityAsObj as IHasCreationTime; if (entityWithCreationTime == null) { //Object does not implement IHasCreationTime return; } if (entityWithCreationTime.CreationTime == default(DateTime)) { AbpDebug.WriteLine($"Clock.Provider:{Clock.Provider}"); entityWithCreationTime.CreationTime = Clock.Now; } if (!(entityAsObj is ICreationAudited)) { //Object does not implement ICreationAudited return; } if (!userId.HasValue) { //Unknown user return; } var entity = entityAsObj as ICreationAudited; if (entity.CreatorUserId != null) { //CreatorUserId is already set return; } if (multiTenancyConfig?.IsEnabled == true) { if (MultiTenancyHelper.IsMultiTenantEntity(entity) && !MultiTenancyHelper.IsTenantEntity(entity, tenantId)) { //A tenant entitiy is created by host or a different tenant return; } if (tenantId.HasValue && MultiTenancyHelper.IsHostEntity(entity)) { //Tenant user created a host entity return; } } //Finally, set CreatorUserId! entity.CreatorUserId = userId; }
public AbpAntiForgeryConfiguration() { AbpDebug.WriteLine($"执行了{nameof(AbpAntiForgeryConfiguration)}的构造函数"); TokenCookieName = "XSRF-TOKEN"; TokenHeaderName = "X-XSRF-TOKEN"; AuthorizationCookieName = ".AspNet.ApplicationCookie"; AuthorizationCookieApplicationScheme = "Identity.Application"; }
public IActionResult ModelBindingCustomClass() { if (CustomModelBindingModel != null) { AbpDebug.WriteLine($"IModelBinder {nameof(CustomModelBindingModel.Name)}={CustomModelBindingModel.Name},{nameof(CustomModelBindingModel.Age)}={CustomModelBindingModel.Age}"); return(Content(CustomModelBindingModel.ToString())); } return(Content("模型自定义类绑定:未能绑定模型")); }
public IActionResult ModelBindingProperty() { if (!YujianName.IsNullOrEmpty()) { AbpDebug.WriteLine($"Property {nameof(YujianName)}={YujianName}"); AbpDebug.WriteLine($"Properties {nameof(Name)}={Name},{nameof(Age)}={Age}"); } return(Content("模型属性绑定")); }
public AbpWebCommonModuleConfiguration( IApiProxyScriptingConfiguration apiProxyScripting, IAbpAntiForgeryConfiguration abpAntiForgery, IWebEmbeddedResourcesConfiguration embeddedResources, IWebMultiTenancyConfiguration multiTenancy) { AbpDebug.WriteLine($"执行了{nameof(AbpWebCommonModuleConfiguration)}的构造函数"); ApiProxyScripting = apiProxyScripting; AntiForgery = abpAntiForgery; EmbeddedResources = embeddedResources; MultiTenancy = multiTenancy; }
public Startup(IWebHostEnvironment env) { //建造者模式,生成ConfigurationBuilder对象, 将不同的配置文件加入到Configuration实例中 _env = env; var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath)//设置文件的根目录 .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); Configuration = builder.Build(); var connStr = Configuration.GetConnectionString("Default"); AbpDebug.WriteLine($"connStr={connStr}"); }
public override void PreInitialize() { Configuration.Auditing.IsEnabledForAnonymousUsers = true; Configuration.Localization.Languages.Add(new LanguageInfo("en", "English", isDefault: true)); Configuration.Localization.Languages.Add(new LanguageInfo("tr", "Türkçe")); AbpDebug.WriteLine($"{nameof(AbpAspNetCoreDemoCoreModule)}添加AbpAspNetCoreDemoModule的本地化资源配置项"); Configuration.Localization.Sources.Add( new DictionaryBasedLocalizationSource("AbpAspNetCoreDemoModule", new JsonEmbeddedFileLocalizationDictionaryProvider( typeof(AbpAspNetCoreDemoCoreModule).GetAssembly(), "AbpAspNetCoreDemo.Core.Localization.SourceFiles" ) ) ); Configuration.Localization.WrapGivenTextIfNotFound = false; }
public IActionResult Localization() { //第一个参数是source的名字,也就是各个模块注入的时候指定的名称。当该值没找到时,会报错 //第二个参数是要找的资源名称,也就是资源文件中配置的键,当该值没找到时,会返回[参数名],这个括号是可以配置的 //Configuration.Localization.WrapGivenTextIfNotFound = false; 如果配置是这样,那么返回的字符就不会有[] var teststring = LocalizationManager.GetString(LocalizationSourceName, "AboutDescription"); var teststring1 = LocalizationManager.GetString(LocalizationSourceName, "MainMenu1"); //本处返回的就是[Main Menu1] var teststring2 = LocalizationManager.GetString(LocalizationSourceName, "中文变量"); //本处返回的就是[中文变量] var testString3 = L("zhongwen"); AbpDebug.WriteLine($"testString={teststring},testString1={teststring1},testString2={teststring2},testString3={testString3}"); var configurationConnectionString = _configuration.GetConnectionString("Default"); var defaultConnectionString = _otherConfiguration.GetConnectionString("Default"); var culture = Request.Query["culture"]; _configuration.Reload(); return(Content("本地化资源测试")); }
/// <inheritdoc/> public override void PreInitialize() { IocManager.Register <IWebMultiTenancyConfiguration, WebMultiTenancyConfiguration>(); IocManager.Register <IApiProxyScriptingConfiguration, ApiProxyScriptingConfiguration>(); IocManager.Register <IAbpAntiForgeryConfiguration, AbpAntiForgeryConfiguration>(); IocManager.Register <IWebEmbeddedResourcesConfiguration, WebEmbeddedResourcesConfiguration>(); IocManager.Register <IAbpWebCommonModuleConfiguration, AbpWebCommonModuleConfiguration>(); IocManager.Register <IJavaScriptMinifier, NUglifyJavaScriptMinifier>(); Configuration.Modules.AbpWebCommon().ApiProxyScripting.Generators[JQueryProxyScriptGenerator.Name] = typeof(JQueryProxyScriptGenerator); //添加AbpWeb开头的本地化资源配置项 AbpDebug.WriteLine("添加AbpWeb开头的本地化资源配置项"); Configuration.Localization.Sources.Add( new DictionaryBasedLocalizationSource( AbpWebConsts.LocalizaionSourceName, new XmlEmbeddedFileLocalizationDictionaryProvider( typeof(AbpWebCommonModule).GetAssembly(), "Abp.Web.Localization.AbpWebXmlSource" ))); }
/// <summary> /// 把所有的时间数据按照指定的格式进行转换 /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="modelBuilder"></param> /// <param name="entityType"></param> protected void ConfigureGlobalValueConverter <TEntity>(ModelBuilder modelBuilder, IMutableEntityType entityType) where TEntity : class { AbpDebug.WriteLine($"SelfType:{entityType},BaseType:{entityType.BaseType}"); //这里的BaseType,只有当前类有父类的时候,才是不空的。且还有个条件:该类必须是DbContext的DbSet属性。 if (entityType.BaseType == null && !typeof(TEntity).IsDefined(typeof(DisableDateTimeNormalizationAttribute), true) && !typeof(TEntity).IsDefined(typeof(OwnedAttribute), true) && !entityType.IsOwned()) //OwnsOne https://docs.microsoft.com/en-us/ef/core/modeling/owned-entities { var dateTimeValueConverter = new AbpDateTimeValueConverter(); var dateTimePropertyInfos = DateTimePropertyInfoHelper.GetDatePropertyInfos(typeof(TEntity)); dateTimePropertyInfos.DateTimePropertyInfos.ForEach(property => { modelBuilder .Entity <TEntity>() .Property(property.Name) .HasConversion(dateTimeValueConverter); }); } }
/// <summary> /// 定义一个全局过滤方法,类型为泛型。在模型创建时,添加指定的功能 /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="modelBuilder"></param> /// <param name="entityType"></param> protected void ConfigureGlobalFilters <TEntity>(ModelBuilder modelBuilder, IMutableEntityType entityType) where TEntity : class { AbpDebug.WriteLine($"配置全局过滤器,替换泛型参数为实际类型参数:{typeof(TEntity)}"); //https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.metadata.imutableentitytype?view=efcore-5.0 //这里的BaseType,只有当前类有父类的时候,才是不空的。且还有个条件:该类必须是DbContext的DbSet属性。 if (entityType.BaseType == null && ShouldFilterEntity <TEntity>(entityType)) { var filterExpression = CreateFilterExpression <TEntity>(); if (filterExpression != null) { if (entityType.IsKeyless) { modelBuilder.Entity <TEntity>().HasQueryFilter(filterExpression); } else { modelBuilder.Entity <TEntity>().HasQueryFilter(filterExpression); } } } }
public override void OnResultExecuted(ResultExecutedContext context) { AbpDebug.WriteLine($"执行了{nameof(LaobaiResultActionFilter)},{nameof(OnResultExecuted)}"); base.OnResultExecuted(context); }
public override void OnResultExecuting(ResultExecutingContext context) { AbpDebug.WriteLine($"执行了{nameof(LaobaiResultActionFilter)},{nameof(OnResultExecuting)}"); //context.Cancel = true;//设置成true则短路当前操作,后面的返回都是空值 base.OnResultExecuting(context); }
public override void OnActionExecuted(ActionExecutedContext context) { AbpDebug.WriteLine($"执行了{nameof(SurroundClassActionFilterAttribute)},{nameof(OnActionExecuted)},{_name}"); base.OnActionExecuted(context); }
public override void OnActionExecuted(ActionExecutedContext context) { AbpDebug.WriteLine($"执行了{nameof(GlobalRegisteredActionFilterAttribute)},{nameof(OnActionExecuted)},{_settings.Name}"); base.OnActionExecuted(context); }
public IActionResult ModelBindingValidate() { AbpDebug.WriteLine($"{Name},{Age}, ModelState.IsValid={ModelState.IsValid}"); return(Content("模型校验绑定")); }
public override void OnActionExecuted(ActionExecutedContext context) { AbpDebug.WriteLine($"{nameof(HomeController)}.{nameof(OnActionExecuted)} Executed"); base.OnActionExecuted(context); }