Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server-registration): added automagical registration for service… #16

Merged
merged 1 commit into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.3" />
<PackageReference Include="Solid.IoC.Registration" Version="2.3.3" />
<PackageReference Include="Solid.Practices.Modularity" Version="2.3.3" />
</ItemGroup>

Expand Down
16 changes: 0 additions & 16 deletions src/LogoFX.Server.IoC.Registration.Specs.Application/Module.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ProjectReference Include="..\LogoFX.Server.Bootstrapping\LogoFX.Server.Bootstrapping.csproj" />
<ProjectReference Include="..\LogoFX.Server.IoC.Registration.Specs.Application\LogoFX.Server.IoC.Registration.Specs.Application.csproj" />
<ProjectReference Include="..\LogoFX.Server.IoC.Registration.Specs.Domain\LogoFX.Server.IoC.Registration.Specs.Domain.csproj" />
<ProjectReference Include="..\LogoFX.Server.IoC.Registration\LogoFX.Server.IoC.Registration.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ internal static WebApplicationBuilder AddServices(this WebApplicationBuilder web
{
webApplicationBuilder.Services.AddControllers();
var bootstrapper = new Bootstrapper(webApplicationBuilder.Services);
bootstrapper
.Use(new RegisterCustomCompositionModulesMiddleware<BootstrapperBase,
IServiceCollection>())
.Use(new Bootstrapping.UseDefaultRegistrationMethodMiddleware<IHaveRegistrator<IServiceCollection>>());
bootstrapper.Use(new Bootstrapping.UseDefaultRegistrationMethodMiddleware<IHaveRegistrator<IServiceCollection>>());
bootstrapper.Use(new RegisterCustomCompositionModulesMiddleware<BootstrapperBase,
IServiceCollection>());
bootstrapper.Use(new AddServicesMiddleware<BootstrapperBase>());
bootstrapper.Initialize();
return webApplicationBuilder;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Solid.IoC.Registration;

// ReSharper disable once CheckNamespace
namespace LogoFX.Server.IoC.Registration
{
public static partial class ServiceCollectionExtensions
{
private static IServiceCollection AddServicesAsContracts
(this IServiceCollection serviceCollection,
IEnumerable<Assembly> assemblies,
string ending)
{
return serviceCollection.RegisterImplementationsAsContracts(assemblies,
assembliesCollection => assembliesCollection.FindTypesByEnding(ending),
RegistrationMethodContext.GetDefaultRegistrationMethod<IServiceCollection>());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.3" />
<PackageReference Include="Solid.Bootstrapping" Version="2.3.3" />
<PackageReference Include="Solid.IoC.Registration" Version="2.3.3" />
<PackageReference Include="Solid.Practices.Middleware" Version="2.3.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Solid.Bootstrapping;
using Solid.Practices.Composition.Contracts;
using Solid.Practices.Middleware;

// ReSharper disable once CheckNamespace
namespace LogoFX.Server.IoC.Registration
{
public class AddServicesMiddleware<TBootstrapper> :
IMiddleware<TBootstrapper> where TBootstrapper : class, IHaveRegistrator<IServiceCollection>, IAssemblySourceProvider
{
TBootstrapper IMiddleware<TBootstrapper>.Apply(TBootstrapper @object)
{
@object.Registrator.AddServices(@object.Assemblies.ToArray());
return @object;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;

// ReSharper disable once CheckNamespace
namespace LogoFX.Server.IoC.Registration
{
public static partial class ServiceCollectionExtensions
{
public static IServiceCollection AddServices(
this IServiceCollection serviceCollection,
Assembly[] assemblies)
{
return serviceCollection.AddServicesImpl(assemblies);
}

private static IServiceCollection AddServicesImpl(
this IServiceCollection serviceCollection,
Assembly[] assemblies)
{
serviceCollection.AddServicesAsContracts(assemblies, "Service");
return serviceCollection;
}
}
}