Skip to content

Commit

Permalink
Tweaks to assembly scan for asp.net core
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisstraw committed Mar 10, 2024
1 parent 9f49918 commit 4d8baeb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualBasic;

namespace OLT.Core
{
public static class OltServiceCollectionAspnetCoreExtensions
{
/// <summary>
/// Build Default AspNetCore Service and configures Dependency Injection
/// </summary>
/// <param name="services"></param>
/// <param name="action">Invoked after initialized</param>
/// <returns></returns>
public static IServiceCollection AddOltAspNetCore(this IServiceCollection services, Action<IMvcBuilder>? action = null)
{
return AddOltAspNetCore(services, new OltInjectionAssemblyFilter(), action);
}

/// <summary>
/// Build Default AspNetCore Service and configures Dependency Injection
Expand All @@ -15,9 +26,21 @@ public static class OltServiceCollectionAspnetCoreExtensions
/// <param name="action">Invoked after initialized</param>
/// <param name="filter">Assembly Filter</param>
/// <returns></returns>
public static IServiceCollection AddOltAspNetCore(this IServiceCollection services, Action<IMvcBuilder>? action = null, OltInjectionAssemblyFilter? filter = null)
public static IServiceCollection AddOltAspNetCore(this IServiceCollection services, OltInjectionAssemblyFilter filter, Action<IMvcBuilder>? action = null)
{
return AddOltAspNetCore(services, new List<Assembly>(), filter, action);
}

/// <summary>
/// Build Default AspNetCore Service and configures Dependency Injection
/// </summary>
/// <param name="services"></param>
/// <param name="baseAssembly">Assembly to include in scan for interfaces</param>
/// <param name="action">Invoked after initialized</param>
/// <returns></returns>
public static IServiceCollection AddOltAspNetCore(this IServiceCollection services, Assembly baseAssembly, Action<IMvcBuilder>? action = null)
{
return AddOltAspNetCore(services, new List<Assembly>(), action, filter);
return AddOltAspNetCore(services, baseAssembly, null, action);
}

/// <summary>
Expand All @@ -28,15 +51,28 @@ public static IServiceCollection AddOltAspNetCore(this IServiceCollection servic
/// <param name="action">Invoked after initialized</param>
/// <param name="filter">Assembly Filter</param>
/// <returns></returns>
public static IServiceCollection AddOltAspNetCore(this IServiceCollection services, Assembly baseAssembly, Action<IMvcBuilder>? action = null, OltInjectionAssemblyFilter? filter = null)
public static IServiceCollection AddOltAspNetCore(this IServiceCollection services, Assembly baseAssembly, OltInjectionAssemblyFilter filter, Action<IMvcBuilder>? action = null)
{
if (baseAssembly == null)
{
throw new ArgumentNullException(nameof(baseAssembly));
}
return AddOltAspNetCore(services, new List<Assembly>() { baseAssembly }, action, filter);
return AddOltAspNetCore(services, new List<Assembly>() { baseAssembly }, filter, action);
}

/// <summary>
/// Build Default AspNetCore Service and configures Dependency Injection
/// </summary>
/// <param name="services"></param>
/// <param name="baseAssemblies">List of assemblies to include in scan for interfaces</param>
/// <param name="action">Invoked after initialized</param>
/// <returns></returns>
public static IServiceCollection AddOltAspNetCore(this IServiceCollection services, List<Assembly> baseAssemblies, Action<IMvcBuilder>? action = null)
{
return AddOltAspNetCore(services, baseAssemblies, new OltInjectionAssemblyFilter(), action);
}


/// <summary>
/// Build Default AspNetCore Service and configures Dependency Injection
/// </summary>
Expand All @@ -45,7 +81,7 @@ public static IServiceCollection AddOltAspNetCore(this IServiceCollection servic
/// <param name="action">Invoked after initialized</param>
/// <param name="filter">Assembly Filter</param>
/// <returns></returns>
public static IServiceCollection AddOltAspNetCore(this IServiceCollection services, List<Assembly> baseAssemblies, Action<IMvcBuilder>? action = null, OltInjectionAssemblyFilter? filter = null)
public static IServiceCollection AddOltAspNetCore(this IServiceCollection services, List<Assembly> baseAssemblies, OltInjectionAssemblyFilter filter, Action<IMvcBuilder>? action = null)
{

if (services == null)
Expand Down Expand Up @@ -78,9 +114,6 @@ public static IServiceCollection AddOltAspNetCore(this IServiceCollection servic

return services;
}




}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public static IEnumerable<T> GetAllImplements<T>(this Assembly assembly)
/// <returns>Returns an instance for all objects</returns>
public static IEnumerable<T> GetAllImplements<T>(this Assembly[] assemblies)
{
return GetAllImplements<T>(assemblies.ToList());
return GetAllImplements<T>(assemblies.AsEnumerable());
}


Expand Down

0 comments on commit 4d8baeb

Please sign in to comment.