It didn't work; I tried a new project too. Were you able to reproduce at your end?
Our cache needs are very limited and in-memory/in-process is sufficient for it; that's why do not want to try Redis.
I'm sharing the code below; removing/obfuscating many things for privacy but have included bare-minimum set that give you a clear idea.
Here's module code:
[DependsOn(
typeof(AbpAutoMapperModule),
typeof(AbpCachingModule)
)]
public class CustomModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
Configure<AbpAutoMapperOptions>(options => {
options.AddMaps<CustomModule>();
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var service = context
.ServiceProvider
.GetRequiredService<CustomInit>();
service.Initialize();
}
}
Init class:
public class CustomInit : ISingletonDependency
{
private IDistributedCache<CacheItem> _cache;
public CustomInit(
IDistributedCache<CacheItem> cache)
{
_cache = cache;
}
public void Initialize()
{
// load records from API
var records = client.Records.GetAllAsync(request).Result;
// initialize abp cache
foreach (var rec in records) {
_cache.SetAsync(
rec.Id, // Cache key
new CacheItem { Id = rec.Id, Name = rec.Name }, // Cache value
new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromDays(1000) } // Cache options
);
}
}
}
Service class where I'm accessing cache:
public class CustomService : ApplicationService, ICustomService, ITransientDependency
{
private IDistributedCache<CacheItem> _cache;
public CustomService(
IDistributedCache<CacheItem> cache)
{
_cache = cache;
}
public async Task<CacheItem> GetAsync(string id)
{
var rec = await _cache.GetAsync(id); // rec is always null
return rec;
}
}
I think you must be interested in the two files:
public class Auth0UsersManagementModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
Configure<Auth0ConnectionOptions>(
configuration.GetSection("Auth0"));
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var service = context
.ServiceProvider
.GetRequiredService<Auth0UsersManagementInit>();
service.Initialize();
}
}
public class Auth0UsersManagementModuleAutoMapperProfile : Profile
{
public Auth0UsersManagementModuleAutoMapperProfile()
{
CreateMap<UserDto, UserCreateRequest>()
//.ForMember(dest => dest.Prop, opt => opt.Ignore())
//.ForMember(dest => dest.Prop, opt => opt.MapFrom(src => src.Prop))
.AfterMap((src, dest) => {
dest.Connection = "Username-Password-Authentication";
});
CreateMap<UserDto, UserUpdateRequest>()
.ForMember(dest => dest.Password, opt => opt.Ignore())
.AfterMap((src, dest) => {
dest.Connection = "Username-Password-Authentication";
});
CreateMap<User, UserDto>()
.ForMember(dest => dest.Password, opt => opt.Ignore())
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.UserId));
CreateMap<User, UserUpdateRequest>();
}
}
Mapping is called as:
var request = ObjectMapper.Map<UserDto, UserCreateRequest>(user);
Yes, already added; as I said it was working like a charm and then suddenly stopped working.
Hi Mahmut,
I'm talking about here extending an existing with new functionality, precisely in this case, adding another tab to User update modal. Can you provide some more concrete example how to do it without the source code?
Thanks
Hi,
I checked that the source code is not available to us on our license tier; is there any other way to accomplish this without buying the source code?
Thanks