hi
I don't have any suggestions on CQRS
, if you encounter any ABP-related problems, I can help you.
Thanks.
hi
Move your code from PostConfigureServices
to OnApplicationInitialization
The IServiceProvider
will be available on OnApplicationInitialization
hi
We have an article about CQRS
https://abp.io/community/articles/implementing-cqrs-with-mediatr-in-abp-xiqz2iio#gsc.tab=0
Thanks. I will test your project.
hi
Add this class to your solution.
Thanks.
using Volo.Abp.BlobStoring;
using Volo.Abp.BlobStoring.Azure;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
namespace MyCompanyName.MyProjectName.Web;
[Dependency(ReplaceServices = true)]`
[ExposeServices(typeof(IAzureBlobNameCalculator), typeof(DefaultAzureBlobNameCalculator))]
public class MyAzureBlobNameCalculator : DefaultAzureBlobNameCalculator
{
public MyAzureBlobNameCalculator(ICurrentTenant currentTenant)
: base(currentTenant)
{
}
public override string Calculate(BlobProviderArgs args)
{
return CurrentTenant.Id == null
? $"{args.BlobName}"
: $"tenants/{CurrentTenant.Id.Value:D}/{args.BlobName}";
}
}
hi
You can override the DefaultAzureBlobNameCalculator
to remove the host
https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/DefaultAzureBlobNameCalculator.cs#L6-L21
Try resolve the ICachedApplicationConfigurationClient
context.Services.GetRequiredService<ICachedApplicationConfigurationClient>();
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ClientProxies;
using Volo.Abp.AspNetCore.Mvc.Client;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Threading;
using Volo.Abp.Users;
namespace MyCompanyName.MyProjectName.Web;
[ExposeServices(
typeof(ICachedApplicationConfigurationClient),
typeof(MyMvcCachedApplicationConfigurationClient)
)]
public class MyMvcCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency
{
protected IHttpContextAccessor HttpContextAccessor { get; }
protected AbpApplicationConfigurationClientProxy ApplicationConfigurationAppService { get; }
protected AbpApplicationLocalizationClientProxy ApplicationLocalizationClientProxy { get; }
protected ICurrentUser CurrentUser { get; }
protected IDistributedCache<ApplicationConfigurationDto> Cache { get; }
protected AbpAspNetCoreMvcClientCacheOptions Options { get; }
public MyMvcCachedApplicationConfigurationClient(
IDistributedCache<ApplicationConfigurationDto> cache,
AbpApplicationConfigurationClientProxy applicationConfigurationAppService,
ICurrentUser currentUser,
IHttpContextAccessor httpContextAccessor,
AbpApplicationLocalizationClientProxy applicationLocalizationClientProxy,
IOptions<AbpAspNetCoreMvcClientCacheOptions> options)
{
ApplicationConfigurationAppService = applicationConfigurationAppService;
CurrentUser = currentUser;
HttpContextAccessor = httpContextAccessor;
ApplicationLocalizationClientProxy = applicationLocalizationClientProxy;
Options = options.Value;
Cache = cache;
}
public async Task<ApplicationConfigurationDto> GetAsync()
{
var cacheKey = CreateCacheKey();
var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration)
{
return configuration;
}
configuration = (await Cache.GetOrAddAsync(
cacheKey,
async () => await GetRemoteConfigurationAsync(),
() => new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = Options.ApplicationConfigurationDtoCacheAbsoluteExpiration
}
))!;
if (httpContext != null)
{
httpContext.Items[cacheKey] = configuration;
}
return configuration;
}
private async Task<ApplicationConfigurationDto> GetRemoteConfigurationAsync()
{
var config = await ApplicationConfigurationAppService.GetAsync(
new ApplicationConfigurationRequestOptions
{
IncludeLocalizationResources = false
}
);
var localizationDto = await ApplicationLocalizationClientProxy.GetAsync(
new ApplicationLocalizationRequestDto {
CultureName = config.Localization.CurrentCulture.Name,
OnlyDynamics = true
}
);
config.Localization.Resources = localizationDto.Resources;
return config;
}
public ApplicationConfigurationDto Get()
{
var cacheKey = CreateCacheKey();
var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration)
{
return configuration;
}
return AsyncHelper.RunSync(GetAsync);
}
protected virtual string CreateCacheKey()
{
return MvcCachedApplicationConfigurationClientHelper.CreateCacheKey(CurrentUser);
}
}
hi
You can get answers from https://abp.io/faq
Can you take a look?
Thanks.