Skip to content

Commit

Permalink
Squash 2 foreach-loops into 1
Browse files Browse the repository at this point in the history
Also skip modules loading if it is loaded
  • Loading branch information
arenekosreal committed Nov 25, 2024
1 parent 7af91a5 commit 00ac10c
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions E5Renewer/IServiceCollectionExtends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,23 @@ public static IServiceCollection AddUserSecretFile(this IServiceCollection servi

public static IServiceCollection AddModules(this IServiceCollection services, params Assembly[] assemblies)
{
foreach (Assembly assembly in assemblies)
Type[] knownModulesTypes = [
typeof(IModulesChecker),
typeof(IUserSecretLoader),
typeof(IGraphAPICaller),
typeof(IAPIFunction)
];
foreach (Type t in assemblies.SelectMany((assembly) => assembly.IterE5RenewerModules()))
{
foreach (Type t in assembly.IterE5RenewerModules())
ServiceDescriptor service = ServiceDescriptor.Transient(

Check warning on line 51 in E5Renewer/IServiceCollectionExtends.cs

View workflow job for this annotation

GitHub Actions / Run tests (windows-latest)

'implementationType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Transient(Type, Type)'. The return value of method 'System.Collections.Generic.IEnumerator<T>.Current.get' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

Check warning on line 51 in E5Renewer/IServiceCollectionExtends.cs

View workflow job for this annotation

GitHub Actions / Run tests (ubuntu-latest)

'implementationType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Transient(Type, Type)'. The return value of method 'System.Collections.Generic.IEnumerator<T>.Current.get' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

Check warning on line 51 in E5Renewer/IServiceCollectionExtends.cs

View workflow job for this annotation

GitHub Actions / Run tests (macos-latest)

'implementationType' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors' in call to 'Microsoft.Extensions.DependencyInjection.ServiceDescriptor.Transient(Type, Type)'. The return value of method 'System.Collections.Generic.IEnumerator<T>.Current.get' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
knownModulesTypes.FirstOrDefault(
(kt) => t.IsAssignableTo(kt),
typeof(IModule)),
t
);
if (!services.Contains(service))
{
if (t.IsAssignableTo(typeof(IModulesChecker)))
{
services.AddTransient(typeof(IModulesChecker), t);
}
else if (t.IsAssignableTo(typeof(IUserSecretLoader)))
{
services.AddTransient(typeof(IUserSecretLoader), t);
}
else if (t.IsAssignableTo(typeof(IGraphAPICaller)))
{
services.AddTransient(typeof(IGraphAPICaller), t);
}
else if (t.IsAssignableTo(typeof(IAPIFunction)))
{
services.AddTransient(typeof(IAPIFunction), t);
}
else if (t.IsAssignableTo(typeof(IModule)))
{
services.AddTransient(typeof(IModule), t);
}
services.Add(service);
}
}
return services;
Expand Down

0 comments on commit 00ac10c

Please sign in to comment.