Skip to content

Commit

Permalink
Add type specific service loads
Browse files Browse the repository at this point in the history
  • Loading branch information
farajfarook committed Aug 24, 2019
1 parent 0d1516c commit 8886254
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,6 +1,6 @@
env:
global:
- PACKAGE_VERSION="1.2.2"
- PACKAGE_VERSION="1.2.3"
- PACKAGE_ICON="https://www.enbiso.com/logo.svg"
- PACKAGE_PROJECT="https://nlib.enbiso.com"
- PACKAGE_REPO="https://github.com/enbiso/Enbiso.NLib"
Expand Down
7 changes: 5 additions & 2 deletions Enbiso.NLib.DependencyInjection/ServiceExtensions.cs
Expand Up @@ -8,6 +8,9 @@ namespace Enbiso.NLib.DependencyInjection
{
public static class ServiceExtensions
{
public static IServiceCollection AddServices(this IServiceCollection services, params Type[] typeReferences)
=> services.AddServices(typeReferences.Select(t => t.Assembly).ToArray());

public static IServiceCollection AddServices(this IServiceCollection services, params Assembly[] assemblies)
{
assemblies.ToList().ForEach(services.AddServicesForAssembly);
Expand All @@ -16,7 +19,7 @@ public static IServiceCollection AddServices(this IServiceCollection services, p

public static IServiceCollection AddServices(this IServiceCollection services)
{
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
var assemblies = Assembly.GetEntryAssembly().GetReferencedAssemblies().Select(Assembly.Load).ToArray();
return services.AddServices(assemblies);
}

Expand All @@ -28,7 +31,7 @@ private static void AddServicesForAssembly(this IServiceCollection services, Ass
if (service == null) continue;
// Get defined interfaces
var interfaces = service.ServiceTypes.ToList();
// If not specificed add implemented interfaces
// If not specified add implemented interfaces
if (!interfaces.Any()) interfaces.AddRange(type.GetInterfaces());
// If not then self bind
if (!interfaces.Any()) interfaces.Add(type);
Expand Down

0 comments on commit 8886254

Please sign in to comment.