ubeac / ubeac-api

Source of uBeac .NET Core packages
3 stars 2 forks source link

History #119

Closed ilhesam closed 2 years ago

ilhesam commented 2 years ago

New structure change:

Added a new project called uBeac.Core.MongoDB

Why I added a new project?

MongoDBContext and the dependent classes should have been used in uBeac.Core.Repositories.History.MongoDB, but these classes were on uBeac.Core.Repositories.MongoDB. Also, could not reference uBeac.Core.Repositories.MongoDB to uBeac.Core.Repositories.History.MongoDB because circular dependency occurs. So I transferred the common classes of MongoDB to uBeac.Core.MongoDB and referenced uBeac.Core.MongoDB in uBeac.Core.Repositories.MongoDB and uBeac.Core.Repositories.History.MongoDB. Now, we can use uBeac.Core.MongoDB in uBeac.Core.Web.Logging.MongoDB and everywhere needed.

Let's move on!

Refactoring

Removed Register method of HistoryBuilder

// Before:
builder.Services.AddHistory<MongoDBHistoryRepository>().For<User>().Register();

// After:
builder.Services.AddHistory<MongoDBHistoryRepository>().For<User>();

Configured MongoDBContext instead of MongoDBOptions in Program.cs and Supported multiple databases

// Before:
// Does not support multiple databases
builder.Services.AddHistory<MongoDBHistoryRepository>().For<User>().Register();
builder.Services.Configure<MongoDBSettings>(builder.Configuration.GetSection("History"));

// After:
// Support multiple databases
builder.Services.AddMongo<HistoryMongoDBContext>("HistoryConnection");
builder.Services.AddHistory<MongoDBHistoryRepository>().For<User>();

// For example of multiple databases:
builder.Services.AddMongo<UserHistoryMongoDBContext>("UserHistoryConnection");
builder.Services.AddHistory<MongoDBHistoryRepository<UserHistoryMongoDBContext>>().For<User>();

builder.Services.AddMongo<RoleHistoryMongoDBContext>("RoleHistoryConnection");
builder.Services.AddHistory<MongoDBHistoryRepository<RoleHistoryMongoDBContext>>().For<Role>();

Added HistoryDefaults:

builder.Services.AddHistory<MongoDBHistoryRepository>(new HistoryDefaults
{
    Suffix = "_History" // Also can getting from JSON configuration files
}).For<User>();

Changed name RegisteredTypesForHistory to HistoryTypesDictionary.

Changed name HistoryFactory to HistoryManager.

And other minor changes...