Browse Source

Merge branch 'dev' into aspnetcore-3.0

pull/1810/head
Halil İbrahim Kalkan 7 years ago
parent
commit
fca268c816
  1. 32
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/DependencyInjection/AbpAspNetCoreMvcConventionalDependencyRegistrar.cs
  2. 6
      framework/src/Volo.Abp.Caching/Volo/Abp/Caching/CacheOptions.cs
  3. 2
      framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs
  4. 54
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/DependencyInjection/AbpAspNetCoreMvcConventionalRegistrar_Tests.cs
  5. 10
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs
  6. 6
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs
  7. 10
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs
  8. 6
      templates/module/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs
  9. 6
      templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs
  10. 10
      templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs

32
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/DependencyInjection/AbpAspNetCoreMvcConventionalDependencyRegistrar.cs

@ -9,22 +9,36 @@ namespace Volo.Abp.AspNetCore.Mvc.DependencyInjection
{
public class AbpAspNetCoreMvcConventionalRegistrar : DefaultConventionalRegistrar
{
protected override ServiceLifetime? GetServiceLifetimeFromClassHierarcy(Type type)
public override void AddType(IServiceCollection services, Type type)
{
var lifeTime = base.GetServiceLifetimeFromClassHierarcy(type);
if (lifeTime != null)
if (!IsMvcService(type))
{
return lifeTime;
return;
}
if (IsController(type) ||
IsPageModel(type) ||
IsViewComponent(type))
var lifeTime = GetMvcServiceLifetime(type);
var serviceTypes = ExposedServiceExplorer.GetExposedServices(type);
TriggerServiceExposing(services, type, serviceTypes);
foreach (var serviceType in serviceTypes)
{
return ServiceLifetime.Transient;
var serviceDescriptor = ServiceDescriptor.Describe(serviceType, type, lifeTime);
services.Add(serviceDescriptor);
}
}
return null;
protected virtual bool IsMvcService(Type type)
{
return IsController(type) ||
IsPageModel(type) ||
IsViewComponent(type);
}
protected virtual ServiceLifetime GetMvcServiceLifetime(Type type)
{
return ServiceLifetime.Transient;
}
private static bool IsPageModel(Type type)

6
framework/src/Volo.Abp.Caching/Volo/Abp/Caching/CacheOptions.cs

@ -6,6 +6,11 @@ namespace Volo.Abp.Caching
{
public class CacheOptions
{
/// <summary>
/// Cache key prefix.
/// </summary>
public string KeyPrefix { get; set; }
/// <summary>
/// Global Cache entry options.
/// </summary>
@ -21,6 +26,7 @@ namespace Volo.Abp.Caching
{
CacheConfigurators = new List<Func<string, DistributedCacheEntryOptions>>();
GlobalCacheEntryOptions = new DistributedCacheEntryOptions();
KeyPrefix = "";
}
}
}

2
framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs

@ -405,7 +405,7 @@ namespace Volo.Abp.Caching
protected virtual string NormalizeKey(string key)
{
var normalizedKey = "c:" + CacheName + ",k:" + key;
var normalizedKey = "c:" + CacheName + ",k:" + _cacheOption.KeyPrefix + key;
if (!IgnoreMultiTenancy && CurrentTenant.Id.HasValue)
{

54
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/DependencyInjection/AbpAspNetCoreMvcConventionalRegistrar_Tests.cs

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.DependencyInjection;
using Xunit;
namespace Volo.Abp.AspNetCore.Mvc.DependencyInjection
{
public class AbpAspNetCoreMvcConventionalRegistrar_Tests
{
[Fact]
public void Should_Registered_Mvc_Service()
{
//Arrange
var services = new ServiceCollection();
//Act
services.AddConventionalRegistrar(new DefaultConventionalRegistrar());
services.AddConventionalRegistrar(new AbpAspNetCoreMvcConventionalRegistrar());
services.AddTypes(typeof(My_Test_PageModel), typeof(My_Test_Controller), typeof(My_Test_ViewComponent));
//Assert
services.ShouldContainTransient(typeof(My_Test_PageModel));
services.ShouldContainTransient(typeof(My_Test_Controller));
services.ShouldContainTransient(typeof(My_Test_ViewComponent));
var serviceProvider = services.BuildServiceProvider();
serviceProvider.GetServices<My_Test_PageModel>().Count().ShouldBe(1);
serviceProvider.GetServices<My_Test_Controller>().Count().ShouldBe(1);
serviceProvider.GetServices<My_Test_ViewComponent>().Count().ShouldBe(1);
}
}
public class My_Test_PageModel : PageModel
{
}
public class My_Test_Controller : Controller
{
}
public class My_Test_ViewComponent : ViewComponent
{
}
}

10
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs

@ -16,6 +16,7 @@ using Volo.Abp;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Autofac;
using Volo.Abp.Caching;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.VirtualFileSystem;
@ -41,6 +42,7 @@ namespace MyCompanyName.MyProjectName
ConfigureConventionalControllers();
ConfigureAuthentication(context, configuration);
ConfigureLocalization();
ConfigureCache(configuration);
ConfigureVirtualFileSystem(context);
ConfigureRedis(context, configuration, hostingEnvironment);
ConfigureCors(context, configuration);
@ -49,6 +51,14 @@ namespace MyCompanyName.MyProjectName
//ConfigureSwaggerServices(context);
}
private void ConfigureCache(IConfigurationRoot configuration)
{
Configure<CacheOptions>(options =>
{
options.KeyPrefix = "MyProjectName:";
});
}
private void ConfigureVirtualFileSystem(ServiceConfigurationContext context)
{
var hostingEnvironment = context.Services.GetHostingEnvironment();

6
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs

@ -20,6 +20,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.Auditing;
using Volo.Abp.Autofac;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.Caching;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.UI.Navigation.Urls;
@ -91,6 +92,11 @@ namespace MyCompanyName.MyProjectName
options.IsJobExecutionEnabled = false;
});
Configure<CacheOptions>(options =>
{
options.KeyPrefix = "MyProjectName:";
});
context.Services.AddStackExchangeRedisCache(options =>
{
options.Configuration = configuration["Redis:Configuration"];

10
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs

@ -23,6 +23,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.Autofac;
using Volo.Abp.AutoMapper;
using Volo.Abp.Caching;
using Volo.Abp.FeatureManagement;
using Volo.Abp.Http.Client.IdentityModel;
using Volo.Abp.Identity.Web;
@ -69,6 +70,7 @@ namespace MyCompanyName.MyProjectName.Web
var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.GetConfiguration();
ConfigureCache(configuration);
ConfigureUrls(configuration);
ConfigureAuthentication(context, configuration);
ConfigureAutoMapper();
@ -80,6 +82,14 @@ namespace MyCompanyName.MyProjectName.Web
//ConfigureSwaggerServices(context.Services);
}
private void ConfigureCache(IConfigurationRoot configuration)
{
Configure<CacheOptions>(options =>
{
options.KeyPrefix = "MyProjectName:";
});
}
private void ConfigureUrls(IConfigurationRoot configuration)
{
Configure<AppUrlOptions>(options =>

6
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs

@ -11,6 +11,7 @@ using Volo.Abp;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.Autofac;
using Volo.Abp.Caching;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.SqlServer;
using Volo.Abp.Localization;
@ -86,6 +87,11 @@ namespace MyCompanyName.MyProjectName
options.ApiName = "MyProjectName";
});
Configure<CacheOptions>(options =>
{
options.KeyPrefix = "MyProjectName:";
});
context.Services.AddStackExchangeRedisCache(options =>
{
options.Configuration = configuration["Redis:Configuration"];

6
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs

@ -15,6 +15,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
using Volo.Abp.Auditing;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.Autofac;
using Volo.Abp.Caching;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.SqlServer;
@ -106,6 +107,11 @@ namespace MyCompanyName.MyProjectName
options.ApiName = configuration["AuthServer:ApiName"];
});
Configure<CacheOptions>(options =>
{
options.KeyPrefix = "MyProjectName:";
});
context.Services.AddStackExchangeRedisCache(options =>
{
options.Configuration = configuration["Redis:Configuration"];

10
templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs

@ -23,6 +23,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.Autofac;
using Volo.Abp.AutoMapper;
using Volo.Abp.Caching;
using Volo.Abp.Http.Client.IdentityModel;
using Volo.Abp.Identity;
using Volo.Abp.Identity.Web;
@ -73,6 +74,7 @@ namespace MyCompanyName.MyProjectName
var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.GetConfiguration();
ConfigureCache(configuration);
ConfigureUrls(configuration);
ConfigureAuthentication(context, configuration);
ConfigureAutoMapper();
@ -81,6 +83,14 @@ namespace MyCompanyName.MyProjectName
ConfigureMultiTenancy();
ConfigureRedis(context, configuration, hostingEnvironment);
}
private void ConfigureCache(IConfigurationRoot configuration)
{
Configure<CacheOptions>(options =>
{
options.KeyPrefix = "MyProjectName:";
});
}
private void ConfigureUrls(IConfigurationRoot configuration)
{

Loading…
Cancel
Save