Skip to content

Commit

Permalink
Added core defaults for configuration, services, logging, dryioc and …
Browse files Browse the repository at this point in the history
…autofac conventions (#1925)
  • Loading branch information
david-driscoll authored Dec 4, 2024
1 parent f02b8dc commit f8b8b69
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 39 deletions.
58 changes: 34 additions & 24 deletions src/Conventions.Abstractions/ConventionHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static class ConventionHostBuilderExtensions
/// <param name="container">The container.</param>
/// <param name="delegate">The delegate.</param>
/// <param name="priority">The priority.</param>
/// <param name="category">The category.</param>
/// <returns><see cref="ConventionContextBuilder" />.</returns>
public static ConventionContextBuilder SetupConvention(
this ConventionContextBuilder container,
Expand All @@ -43,6 +44,7 @@ public static ConventionContextBuilder SetupConvention(
/// <param name="container">The container.</param>
/// <param name="delegate">The delegate.</param>
/// <param name="priority">The priority.</param>
/// <param name="category">The category.</param>
/// <returns><see cref="ConventionContextBuilder" />.</returns>
public static ConventionContextBuilder SetupConvention(
this ConventionContextBuilder container,
Expand Down Expand Up @@ -121,6 +123,7 @@ Func<IConventionContext, IServiceCollection, ValueTask<IServiceProviderFactory<T
/// <param name="container">The container.</param>
/// <param name="delegate">The delegate.</param>
/// <param name="priority">The priority.</param>
/// <param name="category">The category.</param>
/// <returns><see cref="ConventionContextBuilder" />.</returns>
public static ConventionContextBuilder ConfigureServices(
this ConventionContextBuilder container,
Expand All @@ -131,7 +134,7 @@ public static ConventionContextBuilder ConfigureServices(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(@delegate, priority, category);
container.AppendDelegate(@delegate, priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -141,6 +144,7 @@ public static ConventionContextBuilder ConfigureServices(
/// <param name="container">The container.</param>
/// <param name="delegate">The delegate.</param>
/// <param name="priority">The priority.</param>
/// <param name="category">The category.</param>
/// <returns><see cref="ConventionContextBuilder" />.</returns>
public static ConventionContextBuilder ConfigureServices(
this ConventionContextBuilder container,
Expand All @@ -151,7 +155,7 @@ public static ConventionContextBuilder ConfigureServices(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(@delegate, priority, category);
container.AppendDelegate(@delegate, priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -161,6 +165,7 @@ public static ConventionContextBuilder ConfigureServices(
/// <param name="container">The container.</param>
/// <param name="delegate">The delegate.</param>
/// <param name="priority">The priority.</param>
/// <param name="category">The category.</param>
/// <returns><see cref="ConventionContextBuilder" />.</returns>
public static ConventionContextBuilder ConfigureServices(
this ConventionContextBuilder container,
Expand All @@ -171,7 +176,7 @@ public static ConventionContextBuilder ConfigureServices(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(new ServiceConvention((_, configuration, services) => @delegate(configuration, services)), priority, category);
container.AppendDelegate(new ServiceConvention((_, configuration, services) => @delegate(configuration, services)), priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -181,6 +186,7 @@ public static ConventionContextBuilder ConfigureServices(
/// <param name="container">The container.</param>
/// <param name="delegate">The delegate.</param>
/// <param name="priority">The priority.</param>
/// <param name="category">The category.</param>
/// <returns><see cref="ConventionContextBuilder" />.</returns>
public static ConventionContextBuilder ConfigureServices(
this ConventionContextBuilder container,
Expand All @@ -193,7 +199,7 @@ public static ConventionContextBuilder ConfigureServices(
container.AppendDelegate(
new ServiceAsyncConvention((_, configuration, services, cancellationToken) => @delegate(configuration, services, cancellationToken)),
priority,
category
category ?? ConventionCategory.Core
);
return container;
}
Expand All @@ -204,6 +210,7 @@ public static ConventionContextBuilder ConfigureServices(
/// <param name="container">The container.</param>
/// <param name="delegate">The delegate.</param>
/// <param name="priority">The priority.</param>
/// <param name="category">The category.</param>
/// <returns><see cref="ConventionContextBuilder" />.</returns>
public static ConventionContextBuilder ConfigureServices(
this ConventionContextBuilder container,
Expand All @@ -214,7 +221,7 @@ public static ConventionContextBuilder ConfigureServices(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(new ServiceAsyncConvention((_, configuration, services, _) => @delegate(configuration, services)), priority, category);
container.AppendDelegate(new ServiceAsyncConvention((_, configuration, services, _) => @delegate(configuration, services)), priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -224,6 +231,7 @@ public static ConventionContextBuilder ConfigureServices(
/// <param name="container">The container.</param>
/// <param name="delegate">The delegate.</param>
/// <param name="priority">The priority.</param>
/// <param name="category">The category.</param>
/// <returns><see cref="ConventionContextBuilder" />.</returns>
public static ConventionContextBuilder ConfigureServices(
this ConventionContextBuilder container,
Expand All @@ -234,7 +242,7 @@ public static ConventionContextBuilder ConfigureServices(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(new ServiceConvention((_, _, services) => @delegate(services)), priority, category);
container.AppendDelegate(new ServiceConvention((_, _, services) => @delegate(services)), priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -244,6 +252,7 @@ public static ConventionContextBuilder ConfigureServices(
/// <param name="container">The container.</param>
/// <param name="delegate">The delegate.</param>
/// <param name="priority">The priority.</param>
/// <param name="category">The category.</param>
/// <returns><see cref="ConventionContextBuilder" />.</returns>
public static ConventionContextBuilder ConfigureServices(
this ConventionContextBuilder container,
Expand All @@ -254,7 +263,7 @@ public static ConventionContextBuilder ConfigureServices(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(new ServiceAsyncConvention((_, _, services, _) => @delegate(services)), priority, category);
container.AppendDelegate(new ServiceAsyncConvention((_, _, services, _) => @delegate(services)), priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -264,6 +273,7 @@ public static ConventionContextBuilder ConfigureServices(
/// <param name="container">The container.</param>
/// <param name="delegate">The delegate.</param>
/// <param name="priority">The priority.</param>
/// <param name="category">The category.</param>
/// <returns><see cref="ConventionContextBuilder" />.</returns>
public static ConventionContextBuilder ConfigureServices(
this ConventionContextBuilder container,
Expand All @@ -274,7 +284,7 @@ public static ConventionContextBuilder ConfigureServices(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(new ServiceAsyncConvention((_, _, services, cancellationToken) => @delegate(services, cancellationToken)), priority, category);
container.AppendDelegate(new ServiceAsyncConvention((_, _, services, cancellationToken) => @delegate(services, cancellationToken)), priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -295,7 +305,7 @@ public static ConventionContextBuilder ConfigureLogging(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(@delegate, priority, category);
container.AppendDelegate(@delegate, priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -316,7 +326,7 @@ public static ConventionContextBuilder ConfigureLogging(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(@delegate, priority, category);
container.AppendDelegate(@delegate, priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -337,7 +347,7 @@ public static ConventionContextBuilder ConfigureLogging(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(new LoggingConvention((_, configuration, builder) => @delegate(configuration, builder)), priority, category);
container.AppendDelegate(new LoggingConvention((_, configuration, builder) => @delegate(configuration, builder)), priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -361,7 +371,7 @@ public static ConventionContextBuilder ConfigureLogging(
container.AppendDelegate(
new LoggingAsyncConvention((_, configuration, builder, cancellationToken) => @delegate(configuration, builder, cancellationToken)),
priority,
category
category ?? ConventionCategory.Core
);
return container;
}
Expand All @@ -383,7 +393,7 @@ public static ConventionContextBuilder ConfigureLogging(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(new LoggingAsyncConvention((_, configuration, builder, _) => @delegate(configuration, builder)), priority, category);
container.AppendDelegate(new LoggingAsyncConvention((_, configuration, builder, _) => @delegate(configuration, builder)), priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -404,7 +414,7 @@ public static ConventionContextBuilder ConfigureLogging(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(new LoggingConvention((_, _, builder) => @delegate(builder)), priority, category);
container.AppendDelegate(new LoggingConvention((_, _, builder) => @delegate(builder)), priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -425,7 +435,7 @@ public static ConventionContextBuilder ConfigureLogging(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(new LoggingAsyncConvention((_, _, builder, cancellationToken) => @delegate(builder, cancellationToken)), priority, category);
container.AppendDelegate(new LoggingAsyncConvention((_, _, builder, cancellationToken) => @delegate(builder, cancellationToken)), priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -446,7 +456,7 @@ public static ConventionContextBuilder ConfigureLogging(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(new LoggingAsyncConvention((_, _, builder, _) => @delegate(builder)), priority, category);
container.AppendDelegate(new LoggingAsyncConvention((_, _, builder, _) => @delegate(builder)), priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -467,7 +477,7 @@ public static ConventionContextBuilder ConfigureConfiguration(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(@delegate, priority, category);
container.AppendDelegate(@delegate, priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -488,7 +498,7 @@ public static ConventionContextBuilder ConfigureConfiguration(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(@delegate, priority, category);
container.AppendDelegate(@delegate, priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -509,7 +519,7 @@ public static ConventionContextBuilder ConfigureConfiguration(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(new ConfigurationConvention((_, configuration, builder) => @delegate(configuration, builder)), priority, category);
container.AppendDelegate(new ConfigurationConvention((_, configuration, builder) => @delegate(configuration, builder)), priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -533,7 +543,7 @@ public static ConventionContextBuilder ConfigureConfiguration(
container.AppendDelegate(
new ConfigurationAsyncConvention((_, configuration, builder, cancellationToken) => @delegate(configuration, builder, cancellationToken)),
priority,
category
category ?? ConventionCategory.Core
);
return container;
}
Expand All @@ -555,7 +565,7 @@ public static ConventionContextBuilder ConfigureConfiguration(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(new ConfigurationAsyncConvention((_, configuration, builder, _) => @delegate(configuration, builder)), priority, category);
container.AppendDelegate(new ConfigurationAsyncConvention((_, configuration, builder, _) => @delegate(configuration, builder)), priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -576,7 +586,7 @@ public static ConventionContextBuilder ConfigureConfiguration(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(new ConfigurationConvention((_, _, builder) => @delegate(builder)), priority, category);
container.AppendDelegate(new ConfigurationConvention((_, _, builder) => @delegate(builder)), priority, category ?? ConventionCategory.Core);
return container;
}

Expand All @@ -600,7 +610,7 @@ public static ConventionContextBuilder ConfigureConfiguration(
container.AppendDelegate(
new ConfigurationAsyncConvention((_, _, builder, cancellationToken) => @delegate(builder, cancellationToken)),
priority,
category
category ?? ConventionCategory.Core
);
return container;
}
Expand All @@ -622,7 +632,7 @@ public static ConventionContextBuilder ConfigureConfiguration(
{
ArgumentNullException.ThrowIfNull(container);

container.AppendDelegate(new ConfigurationAsyncConvention((_, _, builder, _) => @delegate(builder)), priority, category);
container.AppendDelegate(new ConfigurationAsyncConvention((_, _, builder, _) => @delegate(builder)), priority, category ?? ConventionCategory.Core);
return container;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Conventions.Autofac/AutofacExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static async ValueTask<ContainerBuilder> ApplyConventionsAsync(
)
{
var configuration = context.Get<IConfiguration>() ?? throw new ArgumentException("Configuration was not found in context");
foreach (var item in context.Conventions.Get<IAutofacConvention, AutofacConvention>())
foreach (var item in context.Conventions.Get<IAutofacConvention, AutofacConvention, IAutofacAsyncConvention, AutofacAsyncConvention>())
{
switch (item)
{
Expand All @@ -47,4 +47,4 @@ public static async ValueTask<ContainerBuilder> ApplyConventionsAsync(

return containerBuilder;
}
}
}
8 changes: 4 additions & 4 deletions src/Conventions.Autofac/AutofacRocketHostExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static ConventionContextBuilder ConfigureAutofac(
{
ArgumentNullException.ThrowIfNull(builder);

builder.AppendDelegate(@delegate, priority, category);
builder.AppendDelegate(@delegate, priority, category ?? ConventionCategory.Core);
return builder;
}

Expand All @@ -71,7 +71,7 @@ public static ConventionContextBuilder ConfigureAutofac(
builder.AppendDelegate(
new AutofacConvention((_, configuration, services, container) => @delegate(configuration, services, container)),
priority,
category
category ?? ConventionCategory.Core
);
return builder;
}
Expand All @@ -93,7 +93,7 @@ public static ConventionContextBuilder ConfigureAutofac(
{
ArgumentNullException.ThrowIfNull(builder);

builder.AppendDelegate(new AutofacConvention((_, _, services, container) => @delegate(services, container)), priority, category);
builder.AppendDelegate(new AutofacConvention((_, _, services, container) => @delegate(services, container)), priority, category ?? ConventionCategory.Core);
return builder;
}

Expand All @@ -114,7 +114,7 @@ public static ConventionContextBuilder ConfigureAutofac(
{
ArgumentNullException.ThrowIfNull(builder);

builder.AppendDelegate(new AutofacConvention((_, _, _, container) => @delegate(container)), priority, category);
builder.AppendDelegate(new AutofacConvention((_, _, _, container) => @delegate(container)), priority, category ?? ConventionCategory.Core);
return builder;
}
}
4 changes: 2 additions & 2 deletions src/Conventions.DryIoc/DryIocExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static async ValueTask<IContainer> ApplyConventionsAsync(
)
{
var configuration = context.Get<IConfiguration>() ?? throw new ArgumentException("Configuration was not found in context");
foreach (var item in context.Conventions.Get<IDryIocConvention, DryIocConvention>())
foreach (var item in context.Conventions.Get<IDryIocConvention, DryIocConvention, IDryIocAsyncConvention, DryIocAsyncConvention>())
{
container = item switch
{
Expand All @@ -47,4 +47,4 @@ public static async ValueTask<IContainer> ApplyConventionsAsync(

return container;
}
}
}
Loading

0 comments on commit f8b8b69

Please sign in to comment.