Skip to content

Commit

Permalink
Add WithMetadata with Func<Type, IEnumerable<KeyValuePair<string, obj…
Browse files Browse the repository at this point in the history
…ect?> for OpenGenericAssemblyScanning
  • Loading branch information
romerod committed Dec 9, 2021
1 parent a6a4d8d commit 2b1acdb
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Autofac/RegistrationExtensions.OpenGenericAssemblyScanning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,27 @@ public static IRegistrationBuilder<TLimit, OpenGenericScanningActivatorData, Dyn
{
return registration.As(t => t.GetOpenGenericImplementedInterfaces());
}

/// <summary>
/// Specify how a type from a scanned assembly provides metadata.
/// </summary>
/// <typeparam name="TLimit">Registration limit type.</typeparam>
/// <typeparam name="TRegistrationStyle">Registration style.</typeparam>
/// <param name="registration">Registration to set metadata on.</param>
/// <param name="metadataMapping">A function mapping the type to a list of metadata items.</param>
/// <returns>Registration builder allowing the registration to be configured.</returns>
public static IRegistrationBuilder<TLimit, OpenGenericScanningActivatorData, TRegistrationStyle>
WithMetadata<TLimit, TRegistrationStyle>(
this IRegistrationBuilder<TLimit, OpenGenericScanningActivatorData, TRegistrationStyle> registration,
Func<Type, IEnumerable<KeyValuePair<string, object?>>> metadataMapping)
{
if (registration == null)
{
throw new ArgumentNullException(nameof(registration));
}

registration.ActivatorData.ConfigurationActions.Add((t, rb) => rb.WithMetadata(metadataMapping(t)));
return registration;
}
}
}

0 comments on commit 2b1acdb

Please sign in to comment.