-
-
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.
Business rules and modules
- Loading branch information
Danny Logsdon
committed
Oct 1, 2024
1 parent
c12eb1a
commit 49bf740
Showing
138 changed files
with
1,106 additions
and
880 deletions.
There are no files selected for viewing
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
47 changes: 0 additions & 47 deletions
47
src/V1/ServiceBricks.Cache.AzureDataTables/Extensions/ApplicationBuilderExtensions.cs
This file was deleted.
Oops, something went wrong.
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
82 changes: 82 additions & 0 deletions
82
src/V1/ServiceBricks.Cache.AzureDataTables/Rule/CacheAzureDataTablesModuleAddRule.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,82 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace ServiceBricks.Cache.AzureDataTables | ||
{ | ||
/// <summary> | ||
/// This rule is executed when the ServiceBricks module is added. | ||
/// </summary> | ||
public sealed class CacheAzureDataTablesModuleAddRule : BusinessRule | ||
{ | ||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
public CacheAzureDataTablesModuleAddRule() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Register the rule | ||
/// </summary> | ||
public static void Register(IBusinessRuleRegistry registry) | ||
{ | ||
registry.Register( | ||
typeof(ModuleAddEvent<CacheAzureDataTablesModule>), | ||
typeof(CacheAzureDataTablesModuleAddRule)); | ||
} | ||
|
||
/// <summary> | ||
/// UnRegister the rule. | ||
/// </summary> | ||
public static void UnRegister(IBusinessRuleRegistry registry) | ||
{ | ||
registry.UnRegister( | ||
typeof(ModuleAddEvent<CacheAzureDataTablesModule>), | ||
typeof(CacheAzureDataTablesModuleAddRule)); | ||
} | ||
|
||
/// <summary> | ||
/// Execute the business rule. | ||
/// </summary> | ||
/// <param name="context"></param> | ||
/// <returns></returns> | ||
public override IResponse ExecuteRule(IBusinessRuleContext context) | ||
{ | ||
var response = new Response(); | ||
|
||
// AI: Make sure the context object is the correct type | ||
if (context == null || context.Object == null) | ||
{ | ||
response.AddMessage(ResponseMessage.CreateError(LocalizationResource.PARAMETER_MISSING, "context")); | ||
return response; | ||
} | ||
var e = context.Object as ModuleAddEvent<CacheAzureDataTablesModule>; | ||
if (e == null || e.DomainObject == null || e.ServiceCollection == null) | ||
{ | ||
response.AddMessage(ResponseMessage.CreateError(LocalizationResource.PARAMETER_MISSING, "context")); | ||
return response; | ||
} | ||
|
||
// AI: Perform logic | ||
var services = e.ServiceCollection; | ||
//var configuration = e.Configuration; | ||
|
||
// AI: Configure all options for the module | ||
|
||
// AI: Add storage services for the module. Each domain object should have its own storage repository | ||
services.AddScoped<IStorageRepository<CacheData>, CacheStorageRepository<CacheData>>(); | ||
|
||
// AI: Add API services for the module. Each DTO should have two registrations, one for the generic IApiService<> and one for the named interface | ||
services.AddScoped<IApiService<CacheDataDto>, CacheDataApiService>(); | ||
services.AddScoped<ICacheDataApiService, CacheDataApiService>(); | ||
|
||
// AI: Register business rules for the module | ||
DomainCreateUpdateDateRule<CacheData>.Register(BusinessRuleRegistry.Instance); | ||
DomainDateTimeOffsetRule<CacheData>.Register(BusinessRuleRegistry.Instance, nameof(CacheData.ExpirationDate)); | ||
ApiConcurrencyByUpdateDateRule<CacheData, CacheDataDto>.Register(BusinessRuleRegistry.Instance); | ||
CacheDataCreateRule.Register(BusinessRuleRegistry.Instance); | ||
DomainQueryPropertyRenameRule<CacheData>.Register(BusinessRuleRegistry.Instance, "StorageKey", "PartitionKey"); | ||
|
||
return response; | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/V1/ServiceBricks.Cache.AzureDataTables/Rule/CacheAzureDataTablesModuleStartRule.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,78 @@ | ||
using Azure.Data.Tables; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using ServiceBricks.Storage.AzureDataTables; | ||
|
||
namespace ServiceBricks.Cache.AzureDataTables | ||
{ | ||
/// <summary> | ||
/// This rule is executed when the ServiceBricks module is added. | ||
/// </summary> | ||
public sealed class CacheAzureDataTablesModuleStartRule : BusinessRule | ||
{ | ||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
public CacheAzureDataTablesModuleStartRule() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Register the rule | ||
/// </summary> | ||
public static void Register(IBusinessRuleRegistry registry) | ||
{ | ||
registry.Register( | ||
typeof(ModuleStartEvent<CacheAzureDataTablesModule>), | ||
typeof(CacheAzureDataTablesModuleStartRule)); | ||
} | ||
|
||
/// <summary> | ||
/// UnRegister the rule. | ||
/// </summary> | ||
public static void UnRegister(IBusinessRuleRegistry registry) | ||
{ | ||
registry.UnRegister( | ||
typeof(ModuleStartEvent<CacheAzureDataTablesModule>), | ||
typeof(CacheAzureDataTablesModuleStartRule)); | ||
} | ||
|
||
/// <summary> | ||
/// Execute the business rule. | ||
/// </summary> | ||
/// <param name="context"></param> | ||
/// <returns></returns> | ||
public override IResponse ExecuteRule(IBusinessRuleContext context) | ||
{ | ||
var response = new Response(); | ||
|
||
// AI: Make sure the context object is the correct type | ||
if (context == null || context.Object == null) | ||
{ | ||
response.AddMessage(ResponseMessage.CreateError(LocalizationResource.PARAMETER_MISSING, "context")); | ||
return response; | ||
} | ||
var e = context.Object as ModuleStartEvent<CacheAzureDataTablesModule>; | ||
if (e == null || e.DomainObject == null || e.ApplicationBuilder == null) | ||
{ | ||
response.AddMessage(ResponseMessage.CreateError(LocalizationResource.PARAMETER_MISSING, "context")); | ||
return response; | ||
} | ||
|
||
// AI: Perform logic | ||
|
||
// AI: Get the connection string | ||
var configuration = e.ApplicationBuilder.ApplicationServices.GetRequiredService<IConfiguration>(); | ||
var connectionString = configuration.GetAzureDataTablesConnectionString( | ||
CacheAzureDataTablesConstants.APPSETTING_CONNECTION_STRING); | ||
|
||
// AI: Create each table in the module | ||
TableClient tableClient = new TableClient( | ||
connectionString, | ||
CacheAzureDataTablesConstants.GetTableName(nameof(CacheData))); | ||
tableClient.CreateIfNotExists(); | ||
|
||
return response; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.