-
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.
Merge branch 'master' into renovate/jetbrains
- Loading branch information
Showing
12 changed files
with
257 additions
and
7 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
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,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd"> | ||
<metadata> | ||
<id>Rocket.Surgery.Airframe.Microsoft.Extensions.DependencyInjection</id> | ||
<version>$version$</version> | ||
<authors>RLittlesII</authors> | ||
<owners>Rocket Surgeons Guild</owners> | ||
<copyright>Copyright Rodney Littles, II © 2021</copyright> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<description>ReactiveUI base view model abstractions.</description> | ||
<projectUrl>https://github.com/RocketSurgeonsGuild/Airframe.git</projectUrl> | ||
<repository type="git" url="https://github.com/RocketSurgeonsGuild/Airframe"/> | ||
<iconUrl>https://raw.githubusercontent.com/RocketSurgeonsGuild/graphics/master/png/social-square-thrust-rounded.png</iconUrl> | ||
<tags>MicrosoftDependencyInjection Xamarin MVVM</tags> | ||
</metadata> | ||
<files> | ||
<file src="..\src\MicrosoftDependencyInjection\bin\$configuration$\netstandard2.0\Rocket.Surgery.Airframe.Microsoft.Extensions.DependencyInjection.dll" target="lib\netstandard2.0" /> | ||
<file src="..\src\MicrosoftDependencyInjection\bin\$configuration$\netstandard2.0\Rocket.Surgery.Airframe.Microsoft.Extensions.DependencyInjection.pdb" target="lib\netstandard2.0" /> | ||
<file src="..\src\MicrosoftDependencyInjection\bin\$configuration$\net6.0\Rocket.Surgery.Airframe.Microsoft.Extensions.DependencyInjection.dll" target="lib\net6.0" /> | ||
<file src="..\src\MicrosoftDependencyInjection\bin\$configuration$\net6.0\Rocket.Surgery.Airframe.Microsoft.Extensions.DependencyInjection.pdb" target="lib\net6.0" /> | ||
</files> | ||
</package> |
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
89 changes: 89 additions & 0 deletions
89
src/MicrosoftDependencyInjection/DependencyInjectionExtensions.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,89 @@ | ||
using System; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Rocket.Surgery.Airframe.Microsoft.Extensions.DependencyInjection | ||
{ | ||
/// <summary> | ||
/// Extensions for <see cref="Microsoft.Extensions.DependencyInjection"/>. | ||
/// </summary> | ||
public static class DependencyInjectionExtensions | ||
{ | ||
/// <summary> | ||
/// Configures the <see cref="IOptions{TOptions}"/> for the service collection. | ||
/// </summary> | ||
/// <param name="serviceCollection">The service collection.</param> | ||
/// <typeparam name="T">The option type.</typeparam> | ||
/// <returns>The service collection with options registered.</returns> | ||
public static IServiceCollection ConfigureOptions<T>(this IServiceCollection serviceCollection) | ||
where T : class | ||
{ | ||
serviceCollection | ||
.AddOptions<T>() | ||
.Configure((T settings, IConfiguration config) => config.Bind(settings)); | ||
|
||
return serviceCollection; | ||
} | ||
|
||
/// <summary> | ||
/// Configures the app settings for the service collection. | ||
/// </summary> | ||
/// <param name="serviceCollection">The service collection.</param> | ||
/// <param name="configuration">The configuration.</param> | ||
/// <returns>The service collection with ReactiveUI dependencies registered.</returns> | ||
public static IServiceCollection ConfigureAppSettings( | ||
this IServiceCollection serviceCollection, | ||
IConfiguration configuration) | ||
{ | ||
var builder = new ConfigurationBuilder() | ||
.AddJsonFile("appsettings.json", optional: true) | ||
.AddJsonFile("appsettings.dev.json", optional: true); | ||
|
||
serviceCollection.AddSingleton<IConfiguration>(_ => builder.AddConfiguration(configuration).Build()); | ||
|
||
return serviceCollection; | ||
} | ||
|
||
/// <summary> | ||
/// Adds the <see cref="IPlatformInitializer"/> to the <see cref="IServiceCollection"/>. | ||
/// </summary> | ||
/// <param name="serviceCollection">The service collection.</param> | ||
/// <param name="platformInitializer">The platform initializer.</param> | ||
/// <returns>The service collection with platform dependencies registered.</returns> | ||
public static IServiceCollection AddPlatform(this IServiceCollection serviceCollection, IPlatformInitializer platformInitializer) => | ||
platformInitializer.Initialize(serviceCollection); | ||
|
||
/// <summary> | ||
/// Adds the <see cref="IPlatformInitializer"/> to the <see cref="IServiceCollection"/>. | ||
/// </summary> | ||
/// <param name="serviceCollection">The service collection.</param> | ||
/// <param name="target">The target that owns the platform initializer.</param> | ||
/// <param name="startup">The startup.</param> | ||
/// <typeparam name="TTarget">The target type.</typeparam> | ||
/// <returns>The service collection with platform dependencies registered.</returns> | ||
public static IServiceCollection AddPlatform<TTarget>(this IServiceCollection serviceCollection, TTarget target, Func<TTarget, IPlatformInitializer> startup) => | ||
startup(target).Initialize(serviceCollection); | ||
|
||
/// <summary> | ||
/// Registers an <see cref="IApplicationStartup"/> to the service collection. | ||
/// </summary> | ||
/// <param name="serviceCollection">The service collection.</param> | ||
/// <param name="options">The startup options.</param> | ||
/// <typeparam name="T">The startup type.</typeparam> | ||
/// <returns>The service collection with startup dependencies registered.</returns> | ||
public static IServiceCollection AddStartup<T>(this IServiceCollection serviceCollection, Action<StartupOption>? options = null) | ||
where T : class, IApplicationStartup | ||
{ | ||
serviceCollection.AddTransient<IApplicationStartup, T>(); | ||
|
||
if (options != null) | ||
{ | ||
var startupOption = new StartupOption(serviceCollection); | ||
options.Invoke(startupOption); | ||
} | ||
|
||
return serviceCollection; | ||
} | ||
} | ||
} |
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,17 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Rocket.Surgery.Airframe.Microsoft.Extensions.DependencyInjection | ||
{ | ||
/// <summary> | ||
/// Represents an initializer for a specific platform. | ||
/// </summary> | ||
public interface IPlatformInitializer | ||
{ | ||
/// <summary> | ||
/// Initialize the platform. | ||
/// </summary> | ||
/// <param name="serviceCollection">The service collection.</param> | ||
/// <returns>The service collection with platform dependencies registered.</returns> | ||
public IServiceCollection Initialize(IServiceCollection serviceCollection); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/MicrosoftDependencyInjection/IServiceCollectionModule.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,17 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Rocket.Surgery.Airframe.Microsoft.Extensions.DependencyInjection | ||
{ | ||
/// <summary> | ||
/// Interface that represents a module that groups registrations to the <see cref="IServiceCollection"/>. | ||
/// </summary> | ||
public interface IServiceCollectionModule | ||
{ | ||
/// <summary> | ||
/// Loads the provided <see cref="IServiceCollection"/> with <see cref="ServiceDescriptor"/>. | ||
/// </summary> | ||
/// <param name="serviceCollection">The service collection.</param> | ||
/// <returns>The service collection with dependencies registered.</returns> | ||
IServiceCollection Load(IServiceCollection serviceCollection); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/MicrosoftDependencyInjection/MicrosoftDependencyInjection.csproj
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks> | ||
<Nullable>enable</Nullable> | ||
<AssemblyName>Rocket.Surgery.Airframe.Microsoft.Extensions.DependencyInjection</AssemblyName> | ||
<RootNamespace>Rocket.Surgery.Airframe.Microsoft.Extensions.DependencyInjection</RootNamespace> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" /> | ||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Core\Core.csproj" /> | ||
</ItemGroup> | ||
</Project> |
20 changes: 20 additions & 0 deletions
20
src/MicrosoftDependencyInjection/ServiceCollectionModule.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,20 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Rocket.Surgery.Airframe.Microsoft.Extensions.DependencyInjection | ||
{ | ||
/// <summary> | ||
/// Represents a module to register dependencies against an <see cref="IServiceCollection"/>. | ||
/// </summary> | ||
public abstract class ServiceCollectionModule : IServiceCollectionModule | ||
{ | ||
/// <inheritdoc /> | ||
IServiceCollection IServiceCollectionModule.Load(IServiceCollection serviceCollection) => Load(serviceCollection); | ||
|
||
/// <summary> | ||
/// Loads the provided <see cref="IServiceCollection"/> with <see cref="ServiceDescriptor"/>. | ||
/// </summary> | ||
/// <param name="serviceCollection">The service collection.</param> | ||
/// <returns>The service collection with dependencies registered.</returns> | ||
protected abstract IServiceCollection Load(IServiceCollection serviceCollection); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/MicrosoftDependencyInjection/ServiceCollectionModuleExtensions.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,29 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Rocket.Surgery.Airframe.Microsoft.Extensions.DependencyInjection | ||
{ | ||
/// <summary> | ||
/// Extension methods for registering an <see cref="IServiceCollectionModule"/>. | ||
/// </summary> | ||
public static class ServiceCollectionModuleExtensions | ||
{ | ||
/// <summary> | ||
/// Adds the provided <see cref="IServiceCollectionModule"/> to the <see cref="IServiceCollection"/>. | ||
/// </summary> | ||
/// <param name="serviceCollection">The service collection.</param> | ||
/// <param name="module">The module.</param> | ||
/// <typeparam name="T">The type.</typeparam> | ||
/// <returns>The service collection with dependencies registered.</returns> | ||
public static IServiceCollection AddModule<T>(this IServiceCollection serviceCollection, T module) | ||
where T : IServiceCollectionModule => module.Load(serviceCollection); | ||
|
||
/// <summary> | ||
/// Adds the provided <see cref="IServiceCollectionModule"/> to the <see cref="IServiceCollection"/>. | ||
/// </summary> | ||
/// <param name="serviceCollection">The service collection.</param> | ||
/// <typeparam name="T">The type.</typeparam> | ||
/// <returns>The service collection with dependencies registered.</returns> | ||
public static IServiceCollection AddModule<T>(this IServiceCollection serviceCollection) | ||
where T : IServiceCollectionModule, new() => new T().Load(serviceCollection); | ||
} | ||
} |
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,32 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Rocket.Surgery.Airframe.Microsoft.Extensions.DependencyInjection | ||
{ | ||
/// <summary> | ||
/// Represents a startup options configurator. | ||
/// </summary> | ||
public class StartupOption | ||
{ | ||
private readonly IServiceCollection _serviceCollection; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="StartupOption"/> class. | ||
/// </summary> | ||
/// <param name="serviceCollection">The service collection.</param> | ||
public StartupOption(IServiceCollection serviceCollection) => | ||
_serviceCollection = serviceCollection; | ||
|
||
/// <summary> | ||
/// Adds an <see cref="IStartupOperation"/> to the container. | ||
/// </summary> | ||
/// <typeparam name="T">The operation type.</typeparam> | ||
/// <returns>The option configuration.</returns> | ||
public StartupOption AddOperation<T>() | ||
where T : class, IStartupOperation | ||
{ | ||
_serviceCollection.AddTransient<IStartupOperation, T>(); | ||
|
||
return this; | ||
} | ||
} | ||
} |
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