Skip to content

Commit

Permalink
Fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabii committed Dec 25, 2024
1 parent d9e0855 commit 6e67433
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 157 deletions.
28 changes: 0 additions & 28 deletions src/Cogito.DependencyInjection/IRegistrationAttribute.cs

This file was deleted.

60 changes: 0 additions & 60 deletions src/Cogito.DependencyInjection/RegisterScopedAttribute.cs

This file was deleted.

60 changes: 0 additions & 60 deletions src/Cogito.DependencyInjection/RegisterTransientAttribute.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ namespace Cogito.DependencyInjection
public static class ServiceCollectionExtensions
{

/// <summary>s
/// Registers all types by their decorated registration attributes.
/// </summary>
/// <param name="builder"></param>
/// <param name="assembly"></param>
public static void AddFromAttributes(this IServiceCollection builder, Assembly assembly)
{
if (builder == null)
throw new ArgumentNullException(nameof(builder));
if (assembly == null)
throw new ArgumentNullException(nameof(assembly));

AddFromAttributes(builder, (IEnumerable<Assembly>)[assembly]);
}

/// <summary>s
/// Registers all types by their decorated registration attributes.
/// </summary>
Expand All @@ -26,7 +41,7 @@ public static void AddFromAttributes(this IServiceCollection builder, params Ass
if (assemblies == null)
throw new ArgumentNullException(nameof(assemblies));

builder.AddFromAttributes((IEnumerable<Assembly>)assemblies);
AddFromAttributes(builder, (IEnumerable<Assembly>)assemblies);
}

/// <summary>s
Expand All @@ -41,7 +56,7 @@ public static void AddFromAttributes(this IServiceCollection builder, IEnumerabl
if (assemblies == null)
throw new ArgumentNullException(nameof(assemblies));

builder.AddFromAttributes(assemblies.SelectMany(i => GetAssemblyTypesSafe(i)));
AddFromAttributes(builder, assemblies.SelectMany(i => GetAssemblyTypesSafe(i)));
}

/// <summary>
Expand Down Expand Up @@ -71,16 +86,16 @@ public static void AddFromAttributes(this IServiceCollection builder, IEnumerabl
if (types == null)
throw new ArgumentNullException(nameof(types));

// group by unique registration handler types
// find the set of implementation types and associated registration attributes, ordered
var items = types
.Select(i => i.GetTypeInfo())
.Select(i => new { ImplementationType = i, Attributes = i.GetCustomAttributes(typeof(IRegistrationAttribute), true).Cast<IRegistrationAttribute>() })
.Select(i => new { ImplementationType = i, Attributes = i.GetCustomAttributes(typeof(IServiceRegistrationAttribute), true).Cast<IServiceRegistrationAttribute>() })

Check failure on line 92 in src/Cogito.DependencyInjection/ServiceCollectionAttributeExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

The type or namespace name 'IServiceRegistrationAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 92 in src/Cogito.DependencyInjection/ServiceCollectionAttributeExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

The type or namespace name 'IServiceRegistrationAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 92 in src/Cogito.DependencyInjection/ServiceCollectionAttributeExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

The type or namespace name 'IServiceRegistrationAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 92 in src/Cogito.DependencyInjection/ServiceCollectionAttributeExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

The type or namespace name 'IServiceRegistrationAttribute' could not be found (are you missing a using directive or an assembly reference?)
.SelectMany(i => i.Attributes.Select(j => new { i.ImplementationType, Attribute = j }))
.OrderBy(i => i.Attribute.RegistrationOrder);

// dispatch to associated handler
foreach (var item in items)
item.Attribute.Register(builder, item.ImplementationType);
item.Attribute.Add(builder, item.ImplementationType);
}

/// <summary>
Expand All @@ -95,15 +110,15 @@ public static void AddFromAttributes(this IServiceCollection builder, Type type)
if (type == null)
throw new ArgumentNullException(nameof(type));

// group by unique registration handler types
// find the set of implementation types and associated registration attributes, ordered
var items = type.GetTypeInfo()
.GetCustomAttributes(typeof(IRegistrationAttribute), true)
.Cast<IRegistrationAttribute>()
.GetCustomAttributes(typeof(IServiceRegistrationAttribute), true)

Check failure on line 115 in src/Cogito.DependencyInjection/ServiceCollectionAttributeExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

The type or namespace name 'IServiceRegistrationAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 115 in src/Cogito.DependencyInjection/ServiceCollectionAttributeExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

The type or namespace name 'IServiceRegistrationAttribute' could not be found (are you missing a using directive or an assembly reference?)
.Cast<IServiceRegistrationAttribute>()

Check failure on line 116 in src/Cogito.DependencyInjection/ServiceCollectionAttributeExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

The type or namespace name 'IServiceRegistrationAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 116 in src/Cogito.DependencyInjection/ServiceCollectionAttributeExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

The type or namespace name 'IServiceRegistrationAttribute' could not be found (are you missing a using directive or an assembly reference?)
.OrderBy(i => i.RegistrationOrder);

// dispatch to associated handler
foreach (var item in items)
item.Register(builder, type);
item.Add(builder, type);
}

/// <summary>
Expand Down

0 comments on commit 6e67433

Please sign in to comment.