Skip to content

Commit

Permalink
better namespacing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias Lorenzen committed Oct 24, 2019
1 parent 3bec329 commit 0b7314a
Showing 1 changed file with 12 additions and 2 deletions.
@@ -1,18 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FluffySpoon.Extensions.MicrosoftDependencyInjection
{
public static class RegistrationFilters
{
public static Func<Type, bool> TypesWithinNamespace(string @namespace)
public static Func<Type, bool> TypesWithinNamespace(params string[] namespaceFragments)
{
var @namespace = GetNamespaceFromFragments(namespaceFragments);
return t => t.Namespace?.StartsWith(@namespace) == true;
}

public static Func<Type, bool> TypesWithNamespace(string @namespace)
public static Func<Type, bool> TypesWithNamespace(params string[] namespaceFragments)
{
var @namespace = GetNamespaceFromFragments(namespaceFragments);
return t => t.Namespace == @namespace;
}

Expand All @@ -25,5 +28,12 @@ public static class RegistrationFilters
{
return TypesWithinNamespace(type.Namespace);
}

private static string GetNamespaceFromFragments(string[] namespaceFragments)
{
return namespaceFragments
.DefaultIfEmpty()
.Aggregate((a, b) => a + "." + b);
}
}
}

0 comments on commit 0b7314a

Please sign in to comment.