Skip to content

Commit 951b125

Browse files
authored
Merge pull request #5 from Calabonga/oreder-index-for-both-pipeline
Oreder index for both pipeline
2 parents 3c18955 + 506139a commit 951b125

File tree

6 files changed

+34
-16
lines changed

6 files changed

+34
-16
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
## Что нового
66

7+
### Версия 2.4.2
8+
9+
* Для ConfgureApplication() и для ConfigureServices() теперь есть свой собственный индекс сортировки.
10+
* Переработана информация при логировании в ILogger.
11+
* Исправлены некоторые синтаксические ошибки, а также добавлены новые. :)
12+
713
### Версия 2.4.1
814

915
* Nuget-пакеты обновлены для использования `NET8`

src/Calabonga.AspNetCore.AppDefinitions/AppDefinition.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ public virtual void ConfigureApplication(WebApplication app) { }
2222
/// <summary>
2323
/// Order index for including into pipeline. Default value is 0 for, that's why order index can be undefined.
2424
/// </summary>
25-
public virtual int OrderIndex => 0;
25+
public virtual int ServiceOrderIndex => 0;
26+
27+
/// <summary>
28+
/// Order index for including into pipeline for ConfigureApplication() . Default value is 0 for, that's why order index can be undefined.
29+
/// </summary>
30+
public int ApplicationOrderIndex => 0;
2631

2732
/// <summary>
2833
/// Enable or disable to register into pipeline for the current application Definition.

src/Calabonga.AspNetCore.AppDefinitions/AppDefinitionCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal void AddInfo(AppDefinitionItem definition)
3737
internal IEnumerable<AppDefinitionItem> GetEnabled()
3838
=> Items
3939
.Where(x => x.Definition.Enabled)
40-
.OrderBy(x => x.Definition.OrderIndex);
40+
.OrderBy(x => x.Definition.ServiceOrderIndex);
4141

4242
/// <summary>
4343
///

src/Calabonga.AspNetCore.AppDefinitions/AppDefinitionExtensions.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static void AddDefinitions(this WebApplicationBuilder builder, params Typ
110110
definitionCollection.AddEntryPoint(entryPoint.Name);
111111

112112
var types = entryPoint.Assembly.ExportedTypes.Where(Predicate);
113-
var instances = types.Select(Activator.CreateInstance).Cast<IAppDefinition>().Where(x => x.Enabled).OrderBy(x => x.OrderIndex).ToList();
113+
var instances = types.Select(Activator.CreateInstance).Cast<IAppDefinition>().Where(x => x.Enabled).OrderBy(x => x.ServiceOrderIndex).ToList();
114114

115115
foreach (var definition in instances)
116116
{
@@ -129,11 +129,12 @@ public static void AddDefinitions(this WebApplicationBuilder builder, params Typ
129129
{
130130
if (logger.IsEnabled(LogLevel.Debug))
131131
{
132-
logger.LogDebug("[AppDefinitions for ConfigureServices]: {@AssemblyName}:{@AppDefinitionName} is {EnabledOrDisabled} {ExportEnabled}",
132+
logger.LogDebug("[AppDefinitions ConfigureServices with order index {@ServiceOrderIndex}]: {@AssemblyName}:{@AppDefinitionName} is {EnabledOrDisabled} {ExportEnabled}",
133+
item.Definition.ServiceOrderIndex,
133134
item.AssemblyName,
134135
item.Definition.GetType().Name,
135136
item.Enabled ? "enabled" : "disabled",
136-
item.Exported ? "(exported)" : "export disabled");
137+
item.Exported ? "(exportable)" : string.Empty);
137138
}
138139

139140
item.Definition.ConfigureServices(builder);
@@ -152,10 +153,10 @@ public static void AddDefinitions(this WebApplicationBuilder builder, params Typ
152153
return;
153154
}
154155

155-
logger.LogWarning("[AppDefinitions skipped for ConfigureServices: {Count}", skipped.Count);
156+
logger.LogWarning("[AppDefinitions skipped ConfigureServices: {Count}", skipped.Count);
156157
foreach (var item in skipped)
157158
{
158-
logger.LogWarning("[AppDefinitions skipped for ConfigureServices]: {@AssemblyName}:{@AppDefinitionName} is {EnabledOrDisabled}",
159+
logger.LogWarning("[AppDefinitions skipped ConfigureServices]: {@AssemblyName}:{@AppDefinitionName} is {EnabledOrDisabled}",
159160
item.AssemblyName,
160161
item.Definition.GetType().Name,
161162
item.Enabled ? "enabled" : "disabled");
@@ -181,13 +182,14 @@ public static void UseDefinitions(this WebApplication source)
181182
var logger = source.Services.GetRequiredService<ILogger<AppDefinition>>();
182183
var definitionCollection = source.Services.GetRequiredService<AppDefinitionCollection>();
183184

184-
var items = definitionCollection.GetDistinct().ToList();
185+
var items = definitionCollection.GetDistinct().OrderBy(x => x.Definition.ApplicationOrderIndex).ToList();
185186

186187
foreach (var item in items)
187188
{
188189
if (logger.IsEnabled(LogLevel.Debug))
189190
{
190-
logger.LogDebug("[AppDefinitions for ConfigureApplication]: {@AssemblyName}:{@AppDefinitionName} is {EnabledOrDisabled}",
191+
logger.LogDebug("[AppDefinitions ConfigureApplication with order index {@ApplicationOrderIndex}]: {@AssemblyName}:{@AppDefinitionName} is {EnabledOrDisabled}",
192+
item.Definition.ApplicationOrderIndex,
191193
item.AssemblyName,
192194
item.Definition.GetType().Name,
193195
item.Enabled
@@ -214,14 +216,14 @@ public static void UseDefinitions(this WebApplication source)
214216
return;
215217
}
216218

217-
logger.LogWarning("[AppDefinitions skipped for ConfigureApplication: {Count}", skipped.Count);
219+
logger.LogWarning("[AppDefinitions skipped ConfigureApplication: {Count}", skipped.Count);
218220
foreach (var item in skipped)
219221
{
220-
logger.LogWarning("[AppDefinitions skipped for ConfigureApplication]: {@AssemblyName}:{@AppDefinitionName} is {EnabledOrDisabled} {ExportEnabled}",
222+
logger.LogWarning("[AppDefinitions skipped ConfigureApplication]: {@AssemblyName}:{@AppDefinitionName} is {EnabledOrDisabled} {ExportEnabled}",
221223
item.AssemblyName,
222224
item.Definition.GetType().Name,
223225
item.Enabled ? "enabled" : "disabled",
224-
item.Exported ? "(exported)" : "export disabled");
226+
item.Exported ? "(exportable)" : string.Empty);
225227
}
226228

227229
logger.LogInformation("[AppDefinitions applied: {Count} of {Total}", items.Count, definitionCollection.GetEnabled().Count());

src/Calabonga.AspNetCore.AppDefinitions/Calabonga.AspNetCore.AppDefinitions.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Nullable>enable</Nullable>
77
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
88
<Title>Calabonga.AspNetCore.AppDefinitions</Title>
9-
<Version>2.4.1</Version>
9+
<Version>2.4.2</Version>
1010
<Authors>Calabonga</Authors>
1111
<Company>Calabonga Soft</Company>
1212
<Product>Calabonga.AspNetCore.AppDefinitions</Product>
@@ -18,7 +18,7 @@
1818
<RepositoryUrl>https://github.com/Calabonga/Calabonga.AspNetCore.AppDefinitions</RepositoryUrl>
1919
<RepositoryType>git</RepositoryType>
2020
<PackageTags>calabonga;architecture;application;definitions;minimal-api;nimble-framework</PackageTags>
21-
<PackageReleaseNotes>Additional information added for DEBUG logging. Some errors catching added.</PackageReleaseNotes>
21+
<PackageReleaseNotes>Split order index fot Services and for Application definitions.</PackageReleaseNotes>
2222
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2323
<IncludeSymbols>true</IncludeSymbols>
2424
<IncludeSource>true</IncludeSource>

src/Calabonga.AspNetCore.AppDefinitions/IAppDefinition.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ public interface IAppDefinition
2020
void ConfigureApplication(WebApplication app);
2121

2222
/// <summary>
23-
/// Order index for including into pipeline. Default value is 0 for, that's why order index can be undefined.
23+
/// Order index for including into pipeline for ConfigureServices(). Default value is 0 for, that's why order index can be undefined.
2424
/// </summary>
25-
int OrderIndex { get; }
25+
int ServiceOrderIndex { get; }
26+
27+
/// <summary>
28+
/// Order index for including into pipeline for ConfigureApplication() . Default value is 0 for, that's why order index can be undefined.
29+
/// </summary>
30+
int ApplicationOrderIndex { get; }
2631

2732
/// <summary>
2833
/// Enable or disable to register into pipeline for the current application Definition.

0 commit comments

Comments
 (0)