Which module should this code go in? I try place in [Projectname]ApplicationModule in the Application project and get "The non-generic method 'IAppStartupConfiguration.ReplaceService(Type, Action) cannot be used with type arguments". I place in [Projectname]WebCoreModule in the Web.Core project and nothing happens, AuditLogService is still called. It can not be placed in the [Projectname]CoreModule in the Core project because of dependencies.
In my [Projectname]CoreModule I replace IEntityHistoryStore with MongodbEntityHistoryStore:
Configuration.ReplaceService<IEntityHistoryStore, MongodbEntityHistoryStore>(DependencyLifeStyle.Transient);
. I implement MongodbEntityHistoryStore in the Core project:
using Abp.Dependency;
using Abp.Domain.Repositories;
using Abp.EntityHistory;
using Abp.Timing;
using MongoDB.Bson;
using MongoDB.Driver;
using Nuagecare.Mongodb;
using Nuagecare.MultiTenancy;
using System;
using System.Threading.Tasks;
namespace Nuagecare.App.Mongodb
{
/// <summary>
/// Implements <see cref="IEntityHistoryStore"/> to save entity change informations to Mongodb.
/// </summary>
public class MongodbEntityHistoryStore : IEntityHistoryStore, ITransientDependency
{
private readonly IRepository<EntityChangeSet, long> _changeSetRepository;
private readonly TenantManager _tenantManager;
/// <summary>
/// MongodbEntityHistoryStore
/// </summary>
public MongodbEntityHistoryStore(
IRepository<EntityChangeSet, long> changeSetRepository,
TenantManager tenantManager)
{
_changeSetRepository = changeSetRepository;
_tenantManager = tenantManager;
}
public async Task SaveAsync(EntityChangeSet changeSet)
{
var mongoClient = new MongodbConfig().Initialize();
IMongoDatabase db = mongoClient.GetDatabase(await GetTenancyNameFromTenantId(Convert.ToInt32(changeSet.TenantId)));
var collection = db.GetCollection<BsonDocument>("entityChangeSets");
var document = changeSet.ToBsonDocument();
document.Set("_id", ObjectId.GenerateNewId());
document.Set("CreationTime", Clock.Now);
await collection.InsertOneAsync(document);
}
private async Task<string> GetTenancyNameFromTenantId(int tenantId)
{
var tenant = await _tenantManager.FindByIdAsync(tenantId);
if (tenant == null)
{
return "Projectname";
}
return tenant.TenancyName;
}
}
}
This works great, my entity history data is now in Mongodb and all of my tenants have their own Mongodb database (user rights are set during the create tenant method). Now I need to read the data so I copy the code for AuditLogAppService and refactor it as MongodbAuditLogAppService which is placed in my Application project. I try register my new service in [Projectname]ApplicationModule:
IocManager.Register<IAuditLogAppService, MongodbAuditLogAppService>(DependencyLifeStyle.Transient);
, rebuild, run swagger, but the app still goes to AuditLogAppService. I have also tried register in [Projectname]WebHostModule to no avail.
What do I need to do to register and inject MongodbAuditLogAppService instead of Zero's standard AuditLogAppService?
Thanks, Aaron, it wasn't that simple. I finally managed it by deleting some files from users/appdata, uninstalling and re-installing node and yarn and going round in circles for a couple of hours or so. Nothing to do with Zero, but thanks for your input anyway.
aspnet-core, angular; 5.4.1 I downloaded the latest version of my source to a laptop. I am getting "You have to be inside an angular-cli project in order to use the serve command." when inside the angular project and running any ng command from the terminal. I have updated @angular/cli globally to 6.0.8 (npm install -g @angular/cli@latest). I have installed the latest @angular/cli in the project (npm install @angular/cli@latest). I have uninstalled and re-installed several times, running yarn in between, and rebooted also. My package.json file looks as follows (for devDependencies -
"devDependencies": {
"@angular-devkit/build-angular": "~0.6.0",
"@angular/cli": "^6.0.8",
"@angular/compiler-cli": "6.0.0",
ng -v gives me the following:
angular-cli: 1.0.0-beta.28.3
node: 8.11.3
os: win32 x64
@angular/animations: 6.0.0
@angular/common: 6.0.0
@angular/compiler: 6.0.0
@angular/core: 6.0.0
@angular/forms: 6.0.0
@angular/http: 6.0.0
@angular/platform-browser: 6.0.0
@angular/platform-browser-dynamic: 6.0.0
@angular/platform-server: 6.0.0
@angular/router: 6.0.0
@angular/cli: 6.0.8
@angular/compiler-cli: 6.0.0
I can run the project with npm start but I can not run ng serve or ng build. Any ideas anyone?
@ismcagdas, thanks for getting back. One of the things I like about working with your solution is your diligent attention to all github and forum posts. I don't want to suggest a breaking change when you have other priorities. I can work without this feature but it took me a while to figure out what was happening. I use the settings feature a lot for tenant parameters and the absence of settings in the database just makes it a little bit difficult to work out what's going on when working with third party data providers. Thanks again, keep up the good work!
If my understanding is correct settings are only persisted should they differ from default values declared in your settings provider. I really don't think this is good practise, it may be necessary to read the database for analytics and debugging purposes. The system has to read the database to see if it holds the default value, why then delete it?
Surely settings should be persisted at all times?
Aaron, Perfect, thanks.
dotnet-core, angular, 5.4.1 Hi all, Can anyone point me in the direction of documentation and/or code for token expiration dates? I use an Ionic app to log into Zero.
How long is the token valid for? How does sliding expiration work?
I know this is probably off-piste for Zero and more of a dotnet question but I have looked both in the code base and in the documentation and can find no detail of how to test both the expiration data and sliding expiration. Thanking you in advance....
@ismcagdas, understood, I will fork and send you a request as and when. Thanks.
@alper, nice, thanks. Why don't you guys invite your user base to write articles under a guest account that you could create for £5 per month? That way we could submit articles of interest for the Zero user base and share code and you guys could edit and manage publishing. For example I am about to cut into code for audit logs, system logs and entity history and override standard services replacing them with new services which will persist entries to Mongodb using an Azure Cosmodb wrapper service. I would gladly share my work especially if I knew my article would be reviewed by you guys, the experts. This would have the added advantage of you reviewing my code and suggesting changes where appropriate. I am not a great programmer and sometime find Zero frustrating to work with simply because it is an advanced body of work using concepts and patterns which are way beyond my limited capabilities. Just a thought, let me know if I can help.