Skip to content

Instantly share code, notes, and snippets.

@dimitris-papadimitriou-chr
Created February 20, 2021 17:51
Show Gist options
  • Save dimitris-papadimitriou-chr/83783639641d0b201e8b1ea0a4540e1a to your computer and use it in GitHub Desktop.
Save dimitris-papadimitriou-chr/83783639641d0b201e8b1ea0a4540e1a to your computer and use it in GitHub Desktop.
var rb = RegistrationBuilder.ForDelegate((c, p) =>
{
TService? instance = (TService?)p
.OfType<TypedParameter>()
.FirstOrDefault(tp => tp.Type == typeof(TService))
?.Value;
if (instance == null)
{
throw new DependencyResolutionException(string.Format(CultureInfo.CurrentCulture, RegistrationExtensionsResources.DecoratorRequiresInstanceParameter, typeof(TService).Name));
}
return decorator(c, p, instance);
}).As(service);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment