While using the RAD tool, the core code and the angular are generating but the angular code is not working properly : I am in angular 7
core.js:12301 ERROR Error: Uncaught (in promise): Error: StaticInjectorError(RootModule)[Resources1sComponent -> Http]: StaticInjectorError(Platform: core)[Resources1sComponent -> Http]: NullInjectorError: No provider for Http! Error: StaticInjectorError(RootModule)[Resources1sComponent -> Http]: StaticInjectorError(Platform: core)[Resources1sComponent -> Http]: NullInjectorError: No provider for Http! at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:691) at resolveToken (core.js:928) at tryResolveToken (core.js:872) at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:769) at resolveToken (core.js:928) at tryResolveToken (core.js:872) at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:769) at resolveNgModuleDep (core.js:17435) at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:18124) at resolveNgModuleDep (core.js:17435) at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:691) at resolveToken (core.js:928) at tryResolveToken (core.js:872) at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:769) at resolveToken (core.js:928) at tryResolveToken (core.js:872) at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:769) at resolveNgModuleDep (core.js:17435) at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:18124) at resolveNgModuleDep (core.js:17435) at resolvePromise (zone.js:814) at resolvePromise (zone.js:771) at zone.js:873 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:13842) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188) at drainMicroTaskQueue (zone.js:595) at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:500) at invokeTask (zone.js:1540) defaultErrorLogger @ core.js:12301 push../node_modules/@angular/core/fesm5/core.js.ErrorHandler.handleError @ core.js:12347 next @ core.js:14319 schedulerFn @ core.js:9886 push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:209 push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next @ Subscriber.js:147 push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next @ Subscriber.js:80 push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next @ Subscriber.js:55 push../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next @ Subject.js:47 push../node_modules/@angular/core/fesm5/core.js.EventEmitter.emit @ core.js:9870 (anonymous) @ core.js:13873 push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:388 push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:138 push../node_modules/@angular/core/fesm5/core.js.NgZone.runOutsideAngular @ core.js:13810 onHandleError @ core.js:13873 push../node_modules/zone.js/dist/zone.js.ZoneDelegate.handleError @ zone.js:392 push../node_modules/zone.js/dist/zone.js.Zone.runGuarded @ zone.js:154 _loop_1 @ zone.js:677 api.microtaskDrainDone @ zone.js:686 drainMicroTaskQueue @ zone.js:602 push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask @ zone.js:500 invokeTask @ zone.js:1540 globalZoneAwareCallback @ zone.js:1566
I have already sent you an email. Did you get a chance to look at it ?
Hi -
Can I get an answer to my question ? Thank you in advance.
Any updates?
I am able to add the Azure Vault in th Program.cs and able to add Keys programatically and access them in the Azure Vault. But when it comes to Secret I am having issues. As per the below document I should be able to add the Azure Vault COnfiguration Provider and access the configuration
https://docs.microsoft.com/en-us/aspnet/core/security/key-vault-configuration?view=aspnetcore-2.1
My code :
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
return new WebHostBuilder()
.UseKestrel(opt => opt.AddServerHeader = false)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.ConfigureAppConfiguration((ctx, builder) =>
{
var keyVaultEndpoint = KeyVaultEndpoint;
if (string.IsNullOrEmpty(keyVaultEndpoint)) return;
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyVaultClient = new KeyVaultClient(
new KeyVaultClient.AuthenticationCallback(
azureServiceTokenProvider.KeyVaultTokenCallback));
builder.AddAzureKeyVault(
keyVaultEndpoint, keyVaultClient, new DefaultKeyVaultSecretManager());
});
}
private static string KeyVaultEndpoint => Environment.GetEnvironmentVariable("KEYVAULT_ENDPOINT");
When I trying commenting the configrations in AppSettings.json and adding it in the Azure Vault i am unable to access those values:
e.g. _appConfiguration["ConnectionStrings:Default"]
Am I missing something here ?
I added these classes in the core project.
Error in Error Log :
<br> TokenAuthController' is waiting for the following dependencies: - Service 'DOCUHOLD.EDRMS.MultiTenancy.Cache.ITenantCacheExtensions' which was not registered.
Castle.MicroKernel.Handlers.HandlerException: Can't create component 'DOCUHOLD.EDRMS.Web.Controllers.TokenAuthController' as it has dependencies to be satisfied.
I know I am missing something somewhere but not sure where and how to register it.
public interface ITenantCacheExtensions
{
TenantCacheItemExtensions Get(int tenantId);
TenantCacheItemExtensions Get(string tenancyName);
TenantCacheItemExtensions GetOrNull(string tenancyName);
TenantCacheItemExtensions GetOrNull(int tenantId);
}
public class TenantCacheExtensions<TTenant, TUser> : ITenantCacheExtensions, IEventHandler<EntityChangedEventData<TTenant>>
where TTenant : AbpTenant<TUser>
where TUser : AbpUserBase
{
private readonly ICacheManager _cacheManager;
private readonly IRepository<TTenant> _tenantRepository;
private readonly IUnitOfWorkManager _unitOfWorkManager;
public TenantCacheExtensions(
ICacheManager cacheManager,
IRepository<TTenant> tenantRepository,
IUnitOfWorkManager unitOfWorkManager)
{
_cacheManager = cacheManager;
_tenantRepository = tenantRepository;
_unitOfWorkManager = unitOfWorkManager;
}
public virtual TenantCacheItemExtensions Get(int tenantId)
{
var cacheItem = GetOrNull(tenantId);
if (cacheItem == null)
{
throw new AbpException("There is no tenant with given id: " + tenantId);
}
return cacheItem;
}
public virtual TenantCacheItemExtensions Get(string tenancyName)
{
var cacheItem = GetOrNull(tenancyName);
if (cacheItem == null)
{
throw new AbpException("There is no tenant with given tenancy name: " + tenancyName);
}
return cacheItem;
}
public virtual TenantCacheItemExtensions GetOrNull(string tenancyName)
{
var tenantId = _cacheManager
.GetTenantByNameCache()
.Get(
tenancyName.ToLowerInvariant(),
() => GetTenantOrNull(tenancyName)?.Id
);
return tenantId == null ? null : Get(tenantId.Value);
}
public TenantCacheItemExtensions GetOrNull(int tenantId)
{
return _cacheManager
.GetTenantCache()
.Get(
tenantId,
() =>
{
var tenant = GetTenantOrNull(tenantId);
if (tenant == null)
{
return null;
}
return CreateTenantCacheItem(tenant);
}
);
}
protected virtual TenantCacheItemExtensions CreateTenantCacheItem(TTenant tenant)
{
return new TenantCacheItemExtensions
{
Id = tenant.Id,
Name = tenant.Name,
TenancyName = tenant.TenancyName,
EditionId = tenant.EditionId,
ConnectionString = SimpleStringCipher.Instance.Decrypt(tenant.ConnectionString),
IsActive = tenant.IsActive,
EncryptedAesSessionKey = tenant.EncryptedAesSessionKey,
KeyId = tenant.KeyId
};
}
[UnitOfWork]
protected virtual TTenant GetTenantOrNull(int tenantId)
{
using (_unitOfWorkManager.Current.SetTenantId(null))
{
return _tenantRepository.FirstOrDefault(tenantId);
}
}
[UnitOfWork]
protected virtual TTenant GetTenantOrNull(string tenancyName)
{
using (_unitOfWorkManager.Current.SetTenantId(null))
{
return _tenantRepository.FirstOrDefault(t => t.TenancyName == tenancyName);
}
}
public void HandleEvent(EntityChangedEventData<TTenant> eventData)
{
var existingCacheItem = _cacheManager.GetTenantCache().GetOrDefault(eventData.Entity.Id);
_cacheManager
.GetTenantByNameCache()
.Remove(
existingCacheItem != null
? existingCacheItem.TenancyName.ToLowerInvariant()
: eventData.Entity.TenancyName.ToLowerInvariant()
);
_cacheManager
.GetTenantCache()
.Remove(eventData.Entity.Id);
}
}
[Serializable]
public class TenantCacheItemExtensions
{
public const string CacheName = "AbpZeroTenantCache";
public const string ByNameCacheName = "AbpZeroTenantByNameCache";
public int Id { get; set; }
public string Name { get; set; }
public string TenancyName { get; set; }
public string ConnectionString { get; set; }
public int? EditionId { get; set; }
public bool IsActive { get; set; }
public object CustomData { get; set; }
public byte[] EncryptedAesSessionKey { get; set; }
public string KeyId { get; set; }
}
public static class TenantCacheManagerExtensions
{
public static ITypedCache<int, TenantCacheItemExtensions> GetTenantCache(this ICacheManager cacheManager)
{
return cacheManager.GetCache<int, TenantCacheItemExtensions>(TenantCacheItemExtensions.CacheName);
}
public static ITypedCache<string, int?> GetTenantByNameCache(this ICacheManager cacheManager)
{
return cacheManager.GetCache<string, int?>(Abp.MultiTenancy.TenantCacheItem.ByNameCacheName);
}
}
I have added these four classes :
`public interface ITenantCacheExtensions { TenantCacheItemExtensions Get(int tenantId);
TenantCacheItemExtensions Get(string tenancyName);
TenantCacheItemExtensions GetOrNull(string tenancyName);
TenantCacheItemExtensions GetOrNull(int tenantId);
}``
public class TenantCacheExtensions<TTenant, TUser> : ITenantCacheExtensions, IEventHandler<EntityChangedEventData>
where TTenant : Tenant where TUser : AbpUserBase { private readonly ICacheManager _cacheManager; private readonly IRepository _tenantRepository;
private readonly IUnitOfWorkManager _unitOfWorkManager;
public TenantCacheExtensions(
ICacheManager cacheManager,
IRepository<TTenant> tenantRepository,
IUnitOfWorkManager unitOfWorkManager)
{
_cacheManager = cacheManager;
_tenantRepository = tenantRepository;
_unitOfWorkManager = unitOfWorkManager;
}
public virtual TenantCacheItemExtensions Get(int tenantId)
{
var cacheItem = GetOrNull(tenantId);
if (cacheItem == null)
{
throw new AbpException("There is no tenant with given id: " + tenantId);
}
return cacheItem;
}
public virtual TenantCacheItemExtensions Get(string tenancyName)
{
var cacheItem = GetOrNull(tenancyName);
if (cacheItem == null)
{
throw new AbpException("There is no tenant with given tenancy name: " + tenancyName);
}
return cacheItem;
}
public virtual TenantCacheItemExtensions GetOrNull(string tenancyName)
{
var tenantId = _cacheManager
.GetTenantByNameCache()
.Get(
tenancyName.ToLowerInvariant(),
() => GetTenantOrNull(tenancyName)?.Id
);
return tenantId == null ? null : Get(tenantId.Value);
}
public TenantCacheItemExtensions GetOrNull(int tenantId)
{
return _cacheManager
.GetTenantCache()
.Get(
tenantId,
() =>
{
var tenant = GetTenantOrNull(tenantId);
if (tenant == null)
{
return null;
}
return CreateTenantCacheItem(tenant);
}
);
}
protected virtual TenantCacheItemExtensions CreateTenantCacheItem(TTenant tenant)
{
return new TenantCacheItemExtensions
{
Id = tenant.Id,
Name = tenant.Name,
TenancyName = tenant.TenancyName,
EditionId = tenant.EditionId,
ConnectionString = SimpleStringCipher.Instance.Decrypt(tenant.ConnectionString),
IsActive = tenant.IsActive,
EncryptedAesSessionKey = tenant.EncryptedAesSessionKey,
KeyId = tenant.KeyId
};
}
[UnitOfWork]
protected virtual TTenant GetTenantOrNull(int tenantId)
{
using (_unitOfWorkManager.Current.SetTenantId(null))
{
return _tenantRepository.FirstOrDefault(tenantId);
}
}
[UnitOfWork]
protected virtual TTenant GetTenantOrNull(string tenancyName)
{
using (_unitOfWorkManager.Current.SetTenantId(null))
{
return _tenantRepository.FirstOrDefault(t => t.TenancyName == tenancyName);
}
}
public void HandleEvent(EntityChangedEventData<TTenant> eventData)
{
var existingCacheItem = _cacheManager.GetTenantCache().GetOrDefault(eventData.Entity.Id);
_cacheManager
.GetTenantByNameCache()
.Remove(
existingCacheItem != null
? existingCacheItem.TenancyName.ToLowerInvariant()
: eventData.Entity.TenancyName.ToLowerInvariant()
);
_cacheManager
.GetTenantCache()
.Remove(eventData.Entity.Id);
}
}`
`
public object CustomData { get; set; }
public byte[] EncryptedAesSessionKey { get; set; }
public string KeyId { get; set; }
}`
`public static class TenantCacheManagerExtensions
{
public static ITypedCache<int, TenantCacheItemExtensions> GetTenantCache(this ICacheManager cacheManager)
{
return cacheManager.GetCache<int, TenantCacheItemExtensions>(TenantCacheItemExtensions.CacheName);
}
public static ITypedCache<string, int?> GetTenantByNameCache(this ICacheManager cacheManager)
{
return cacheManager.GetCache<string, int?>(Abp.MultiTenancy.TenantCacheItem.ByNameCacheName);
}
}`
Then I made changes to ITenanctCache in TokenAuthController
`public class TokenAuthController : EDRMSControllerBase { private const string UserIdentifierClaimType = "http://aspnetzero.com/claims/useridentifier";
private readonly LogInManager _logInManager;
private readonly ITenantCacheExtensions _tenantCache;`
When I do this I get Internal Server error, when I change it to ITenantCache it works fine.
Am i missing something ?
I am trying to add two columns to Tenant table and also trying to handle the Tenant Cache.
I am geting the below error :
Severity Code Description Project File Line Suppression State Error CS1593 Delegate 'Func<int, TenantCacheItem>' does not take 0 arguments TenantCustomCache.cs 74 Active
` ** public TenantCustomCacheItem GetOrNull(int tenantId)
{
return _cacheManager
.GetTenantCache()
.Get(
tenantId,
() =>
{
var tenant = GetTenantOrNull(tenantId);
if (tenant == null)
{
return null;
}
return CreateTenantCacheItem(tenant);
}
);
}**`
Below is the entire class ` public class TenantCustomCache<TTenant, TUser> : ITenantCustomCacheItem, IEventHandler<EntityChangedEventData
public TenantCustomCache(
ICacheManager cacheManager,
IRepository<TTenant> tenantRepository,
IUnitOfWorkManager unitOfWorkManager)
{
_cacheManager = cacheManager;
_tenantRepository = tenantRepository;
_unitOfWorkManager = unitOfWorkManager;
}
public virtual TenantCustomCacheItem Get(int tenantId)
{
var cacheItem = GetOrNull(tenantId);
if (cacheItem == null)
{
throw new AbpException("There is no tenant with given id: " + tenantId);
}
return cacheItem;
}
public virtual TenantCustomCacheItem Get(string tenancyName)
{
var cacheItem = GetOrNull(tenancyName);
if (cacheItem == null)
{
throw new AbpException("There is no tenant with given tenancy name: " + tenancyName);
}
return cacheItem;
}
public virtual TenantCustomCacheItem GetOrNull(string tenancyName)
{
var tenantId = _cacheManager
.GetTenantByNameCache()
.Get(
tenancyName.ToLowerInvariant(),
() => GetTenantOrNull(tenancyName)?.Id
);
return tenantId == null ? null : Get(tenantId.Value);
}
** public TenantCustomCacheItem GetOrNull(int tenantId)
{
return _cacheManager
.GetTenantCache()
.Get(
tenantId,
() =>
{
var tenant = GetTenantOrNull(tenantId);
if (tenant == null)
{
return null;
}
return CreateTenantCacheItem(tenant);
}
);
}**
protected virtual TenantCustomCacheItem CreateTenantCacheItem(TTenant tenant)
{
return new TenantCustomCacheItem
{
Id = tenant.Id,
Name = tenant.Name,
TenancyName = tenant.TenancyName,
EditionId = tenant.EditionId,
ConnectionString = SimpleStringCipher.Instance.Decrypt(tenant.ConnectionString),
IsActive = tenant.IsActive,
EncryptedAesSessionKey = tenant.EncryptedAesSessionKey,
KeyId = tenant.KeyId
};
}
[UnitOfWork]
protected virtual TTenant GetTenantOrNull(int tenantId)
{
using (_unitOfWorkManager.Current.SetTenantId(null))
{
return _tenantRepository.FirstOrDefault(tenantId);
}
}
[UnitOfWork]
protected virtual TTenant GetTenantOrNull(string tenancyName)
{
using (_unitOfWorkManager.Current.SetTenantId(null))
{
return _tenantRepository.FirstOrDefault(t => t.TenancyName == tenancyName);
}
}
public void HandleEvent(EntityChangedEventData<TTenant> eventData)
{
var existingCacheItem = _cacheManager.GetTenantCache().GetOrDefault(eventData.Entity.Id);
_cacheManager
.GetTenantByNameCache()
.Remove(
existingCacheItem != null
? existingCacheItem.TenancyName.ToLowerInvariant()
: eventData.Entity.TenancyName.ToLowerInvariant()
);
_cacheManager
.GetTenantCache()
.Remove(eventData.Entity.Id);
}
}`