Skip to content

Commit 225592c

Browse files
committed
Refactored facility types to interfaces.
1 parent befb96d commit 225592c

File tree

17 files changed

+68
-217
lines changed

17 files changed

+68
-217
lines changed

DependencyInjection/src/AppCore.Extensions.DependencyInjection.Abstractions/Facilities/Facility.cs

Lines changed: 0 additions & 134 deletions
This file was deleted.

DependencyInjection/src/AppCore.Extensions.DependencyInjection.Abstractions/Facilities/FacilityExtension.cs

Lines changed: 0 additions & 46 deletions
This file was deleted.

DependencyInjection/src/AppCore.Extensions.DependencyInjection.Abstractions/Facilities/FacilityReflectionBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public IFacilityReflectionBuilder AddResolver<T>(Action<T>? configure = null)
3232
return AddResolver(resolver);
3333
}
3434

35-
public IReadOnlyCollection<Facility> Resolve()
35+
public IReadOnlyCollection<IFacility> Resolve()
3636
{
3737
return _resolvers.SelectMany(s => s.Resolve())
3838
.ToList()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed under the MIT License.
2+
// Copyright (c) 2018-2022 the AppCore .NET project.
3+
4+
using Microsoft.Extensions.DependencyInjection;
5+
6+
namespace AppCore.Extensions.DependencyInjection.Facilities;
7+
8+
/// <summary>
9+
/// Represents a facility.
10+
/// </summary>
11+
public interface IFacility
12+
{
13+
/// <summary>
14+
/// Must be implemented to register services with the <see cref="IServiceCollection"/>.
15+
/// </summary>
16+
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
17+
void ConfigureServices(IServiceCollection services);
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed under the MIT License.
2+
// Copyright (c) 2018-2022 the AppCore .NET project.
3+
4+
using Microsoft.Extensions.DependencyInjection;
5+
6+
namespace AppCore.Extensions.DependencyInjection.Facilities;
7+
8+
/// <summary>
9+
/// Represents an extension for a facility.
10+
/// </summary>
11+
public interface IFacilityExtension<T>
12+
where T : IFacility
13+
{
14+
/// <summary>
15+
/// Must be implemented to register services with the <see cref="IServiceCollection"/>.
16+
/// </summary>
17+
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
18+
void ConfigureServices(IServiceCollection services);
19+
}

DependencyInjection/src/AppCore.Extensions.DependencyInjection.Abstractions/Facilities/IFacilityResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ public interface IFacilityResolver
1414
/// Resolves facilities.
1515
/// </summary>
1616
/// <returns>The <see cref="IEnumerable{T}"/> of facilities.</returns>
17-
IEnumerable<Facility> Resolve();
17+
IEnumerable<IFacility> Resolve();
1818
}

DependencyInjection/src/AppCore.Extensions.DependencyInjection.Abstractions/FacilityServiceCollectionExtensions.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public static class FacilityServiceCollectionExtensions
1919
/// <summary>
2020
/// Adds the facility with the specified type to the <see cref="IServiceCollection"/>.
2121
/// </summary>
22-
/// <typeparam name="T">The type of the <see cref="Facility"/>.</typeparam>
22+
/// <typeparam name="T">The type of the <see cref="IFacility"/>.</typeparam>
2323
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
2424
/// <param name="configure">The delegate to configure the facility.</param>
2525
/// <returns>The <see cref="IServiceCollection"/>.</returns>
2626
public static IServiceCollection AddFacility<T>(this IServiceCollection services, Action<T>? configure = null)
27-
where T : Facility
27+
where T : IFacility
2828
{
2929
return AddFacility(services, typeof(T), f => configure?.Invoke((T) f));
3030
}
@@ -33,26 +33,26 @@ public static IServiceCollection AddFacility<T>(this IServiceCollection services
3333
/// Adds the facility with the specified type to the <see cref="IServiceCollection"/>.
3434
/// </summary>
3535
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
36-
/// <param name="facilityType">The type of the <see cref="Facility"/>.</param>
36+
/// <param name="facilityType">The type of the <see cref="IFacility"/>.</param>
3737
/// <param name="configure">The delegate to configure the facility.</param>
3838
/// <returns>The <see cref="IServiceCollection"/>.</returns>
3939
public static IServiceCollection AddFacility(
4040
this IServiceCollection services,
4141
Type facilityType,
42-
Action<Facility>? configure = null)
42+
Action<IFacility>? configure = null)
4343
{
4444
Ensure.Arg.NotNull(services);
4545
Ensure.Arg.NotNull(facilityType);
46-
Ensure.Arg.OfType(facilityType, typeof(Facility));
46+
Ensure.Arg.OfType(facilityType, typeof(IFacility));
4747

4848
services.TryAddTransient<IActivator, ServiceProviderActivator>();
4949

5050
var serviceProvider = new ServiceCollectionServiceProvider(services);
5151
var activator = serviceProvider.GetRequiredService<IActivator>();
5252

53-
var facility = (Facility)activator.CreateInstance(facilityType);
53+
var facility = (IFacility)activator.CreateInstance(facilityType);
5454
configure?.Invoke(facility);
55-
facility.ConfigureServices(activator, services);
55+
facility.ConfigureServices(services);
5656

5757
return services;
5858
}

DependencyInjection/src/AppCore.Extensions.DependencyInjection.Abstractions/ReflectionServiceCollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ public static IServiceCollection AddFacilitiesFrom(
158158

159159
configure(builder);
160160

161-
foreach (Facility facility in builder.Resolve())
161+
foreach (IFacility facility in builder.Resolve())
162162
{
163-
facility.ConfigureServices(activator, services);
163+
facility.ConfigureServices(services);
164164
}
165165

166166
return services;

DependencyInjection/src/AppCore.Extensions.DependencyInjection.AssemblyExtensions/Facilities/AssemblyFacilityResolver.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace AppCore.Extensions.DependencyInjection.Facilities;
1313

1414
/// <summary>
15-
/// Builds an <see cref="IEnumerable{T}"/> of <see cref="Facility"/> by scanning assemblies.
15+
/// Builds an <see cref="IEnumerable{T}"/> of <see cref="IFacility"/> by scanning assemblies.
1616
/// </summary>
1717
public class AssemblyFacilityResolver : IFacilityResolver
1818
{
@@ -98,9 +98,9 @@ public AssemblyFacilityResolver ClearDefaultFilters()
9898
}
9999

100100
/// <inheritdoc />
101-
IEnumerable<Facility> IFacilityResolver.Resolve()
101+
IEnumerable<IFacility> IFacilityResolver.Resolve()
102102
{
103-
var scanner = new AssemblyScanner(typeof(Facility), _assemblies)
103+
var scanner = new AssemblyScanner(typeof(IFacility), _assemblies)
104104
{
105105
IncludePrivateTypes = _withPrivateTypes
106106
};
@@ -112,6 +112,6 @@ IEnumerable<Facility> IFacilityResolver.Resolve()
112112
scanner.Filters.Add(filter);
113113

114114
return scanner.ScanAssemblies()
115-
.Select(facilityType => (Facility) _activator.CreateInstance(facilityType));
115+
.Select(facilityType => (IFacility) _activator.CreateInstance(facilityType));
116116
}
117117
}

DependencyInjection/src/AppCore.Extensions.DependencyInjection.DependencyModelExtensions/Facilities/DependencyContextFacilityResolver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace AppCore.DependencyInjection.Facilities;
1515

1616
/// <summary>
17-
/// Builds an <see cref="IEnumerable{T}"/> of <see cref="Facility"/> by scanning assemblies in a
17+
/// Builds an <see cref="IEnumerable{T}"/> of <see cref="IFacility"/> by scanning assemblies in a
1818
/// <see cref="DependencyContext"/>.
1919
/// </summary>
2020
public class DependencyContextFacilityResolver : IFacilityResolver
@@ -88,7 +88,7 @@ public DependencyContextFacilityResolver ClearDefaultFilters()
8888
}
8989

9090
/// <inheritdoc />
91-
IEnumerable<Facility> IFacilityResolver.Resolve()
91+
IEnumerable<IFacility> IFacilityResolver.Resolve()
9292
{
9393
return ((IFacilityResolver)_resolver).Resolve();
9494
}

0 commit comments

Comments
 (0)