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.
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.
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 inuBeac.Core.Repositories.History.MongoDB
, but these classes were onuBeac.Core.Repositories.MongoDB
. Also, could not referenceuBeac.Core.Repositories.MongoDB
touBeac.Core.Repositories.History.MongoDB
because circular dependency occurs. So I transferred the common classes of MongoDB touBeac.Core.MongoDB
and referenceduBeac.Core.MongoDB
inuBeac.Core.Repositories.MongoDB
anduBeac.Core.Repositories.History.MongoDB
. Now, we can useuBeac.Core.MongoDB
inuBeac.Core.Web.Logging.MongoDB
and everywhere needed.Let's move on!
Refactoring
Removed
Register
method ofHistoryBuilder
Configured
MongoDBContext
instead ofMongoDBOptions
in Program.cs and Supported multiple databasesAdded
HistoryDefaults
:Changed name
RegisteredTypesForHistory
toHistoryTypesDictionary
.Changed name
HistoryFactory
toHistoryManager
.And other minor changes...