-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💾 Feat: Basic structure for Dependency Injection
- Loading branch information
1 parent
e380d0e
commit c56a8df
Showing
15 changed files
with
211 additions
and
13 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
KitX Website Backend/KitX Website Backend Api/Modules/Accounts/AccountsManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using KitX_Website_Backend.Api.Modules.DataBase; | ||
using KitX_Website_Backend.Api.Modules.Interfaces; | ||
|
||
namespace KitX_Website_Backend.Api.Modules.Accounts; | ||
|
||
public class AccountsManager : IManager | ||
{ | ||
public ILogger<IManager> Logger { get; init; } | ||
|
||
public WebApplication? App { get; init; } | ||
|
||
public AccountsManager(ILogger<AccountsManager> logger, WebApplication app) | ||
{ | ||
Logger = logger; | ||
|
||
App = app; | ||
} | ||
|
||
public AccountsManager Initialize() | ||
{ | ||
using var scope = App!.Services.CreateScope(); | ||
|
||
var provider = scope.ServiceProvider; | ||
|
||
var dbConnector = provider.GetRequiredService<IConnector>(); | ||
|
||
|
||
|
||
return this; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
KitX Website Backend/KitX Website Backend Api/Modules/Accounts/AccountsModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using KitX_Website_Backend.Api.Modules.Accounts; | ||
using KitX_Website_Backend.Api.Modules.Interfaces; | ||
|
||
namespace KitX_Website_Backend.Api.Modules.DataBase; | ||
|
||
public class AccountsModule : IModule | ||
{ | ||
public string Name { get; init; } | ||
|
||
public string Description { get; init; } | ||
|
||
public string Version { get; init; } | ||
|
||
public AccountsModule() | ||
{ | ||
Name = "Accounts"; | ||
|
||
Description = "Manage accounts automatically"; | ||
|
||
Version = "v0.0.1"; | ||
} | ||
|
||
public Type? GetManagerType() => typeof(AccountsManager); | ||
} |
8 changes: 0 additions & 8 deletions
8
KitX Website Backend/KitX Website Backend Api/Modules/DataBase/Connector.cs
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
KitX Website Backend/KitX Website Backend Api/Modules/DataBase/DataBaseModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using KitX_Website_Backend.Api.Modules.Interfaces; | ||
|
||
namespace KitX_Website_Backend.Api.Modules.DataBase; | ||
|
||
public class DataBaseModule : IModule | ||
{ | ||
public string Name { get; init; } | ||
|
||
public string Description { get; init; } | ||
|
||
public string Version { get; init; } | ||
|
||
public DataBaseModule() | ||
{ | ||
Name = "DataBase"; | ||
|
||
Description = "Connects to DataBase and provides methods to operate it"; | ||
|
||
Version = "v0.0.1"; | ||
} | ||
|
||
public Type? GetManagerType() => null; | ||
} |
12 changes: 12 additions & 0 deletions
12
KitX Website Backend/KitX Website Backend Api/Modules/DataBase/Interfaces/IConnector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace KitX_Website_Backend.Api.Modules.DataBase; | ||
|
||
public interface IConnector | ||
{ | ||
public ILogger<IConnector> Logger { get; init; } | ||
|
||
public string ConnectionString { get; init; } | ||
|
||
public bool IsConnected { get; } | ||
|
||
public IConnector Initialize(); | ||
} |
40 changes: 40 additions & 0 deletions
40
KitX Website Backend/KitX Website Backend Api/Modules/DataBase/MongoDbConnector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using MongoDB.Driver; | ||
using MongoDB.Driver.Linq; | ||
|
||
namespace KitX_Website_Backend.Api.Modules.DataBase; | ||
|
||
public class MongoDbConnector(ILogger<IConnector> logger, string connectionString) : IConnector | ||
{ | ||
public ILogger<IConnector> Logger { get; init; } = logger; | ||
|
||
public string ConnectionString { get; init; } = connectionString; | ||
|
||
private MongoClient? mongoClient; | ||
|
||
public bool IsConnected => mongoClient is null; | ||
|
||
public IConnector Initialize() | ||
{ | ||
mongoClient = new(ConnectionString); | ||
|
||
Logger.LogInformation( | ||
"@Init: {name}, Connected: {isConnected}, Connection String: {str}", | ||
nameof(MongoDbConnector), | ||
IsConnected, | ||
ConnectionString | ||
); | ||
|
||
return this; | ||
} | ||
|
||
public IMongoCollection<T>? GetCollection<T>(string dbName, string colName) | ||
{ | ||
return mongoClient?.GetDatabase(dbName).GetCollection<T>(colName); | ||
} | ||
|
||
public IMongoQueryable<T> QueryCollection<T>(string dbName, string colName) | ||
{ | ||
var collection = GetCollection<T>(dbName, colName); | ||
return collection.AsQueryable(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
KitX Website Backend/KitX Website Backend Api/Modules/Interfaces/IManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace KitX_Website_Backend.Api.Modules.Interfaces; | ||
|
||
public interface IManager | ||
{ | ||
public ILogger<IManager> Logger { get; init; } | ||
} |
12 changes: 12 additions & 0 deletions
12
KitX Website Backend/KitX Website Backend Api/Modules/Interfaces/IModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace KitX_Website_Backend.Api.Modules.Interfaces; | ||
|
||
public interface IModule | ||
{ | ||
public string Name { get; init; } | ||
|
||
public string Description { get; init; } | ||
|
||
public string Version { get; init; } | ||
|
||
public Type? GetManagerType(); | ||
} |
23 changes: 23 additions & 0 deletions
23
KitX Website Backend/KitX Website Backend Api/Modules/Kxp/KxpModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using KitX_Website_Backend.Api.Modules.Interfaces; | ||
|
||
namespace KitX_Website_Backend.Api.Modules.Kxp; | ||
|
||
public class KxpModule : IModule | ||
{ | ||
public string Name { get; init; } | ||
|
||
public string Description { get; init; } | ||
|
||
public string Version { get; init; } | ||
|
||
public KxpModule() | ||
{ | ||
Name = "Kxp"; | ||
|
||
Description = "To manage KitX Extension Packages"; | ||
|
||
Version = "v0.0.1"; | ||
} | ||
|
||
public Type? GetManagerType() => null; | ||
} |
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions
23
KitX Website Backend/KitX Website Backend Api/Modules/ModulesManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using KitX_Website_Backend.Api.Modules.DataBase; | ||
using KitX_Website_Backend.Api.Modules.Interfaces; | ||
using KitX_Website_Backend.Api.Modules.Kxp; | ||
|
||
namespace KitX_Website_Backend.Api.Modules; | ||
|
||
public class ModulesManager | ||
{ | ||
public ILogger<ModulesManager> Logger { get; init; } | ||
|
||
public List<IModule> ModulesPool { get; init; } | ||
|
||
public ModulesManager(ILogger<ModulesManager> logger) | ||
{ | ||
Logger = logger; | ||
|
||
ModulesPool = [ | ||
new DataBaseModule(), | ||
new AccountsModule(), | ||
new KxpModule(), | ||
]; | ||
} | ||
} |
Empty file removed
0
KitX Website Backend/KitX Website Backend Api/Modules/Plugins/Storage/Manager.cs
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters