Skip to content

Instantly share code, notes, and snippets.

@xperiandri
Created February 13, 2022 21:51
Show Gist options
  • Save xperiandri/96b0eeb14d6f3e90bbf06473c6ebc4c5 to your computer and use it in GitHub Desktop.
Save xperiandri/96b0eeb14d6f3e90bbf06473c6ebc4c5 to your computer and use it in GitHub Desktop.
type IServiceCollection with
// HACK:
member services.AddAuthorizationWithReflection (configure) =
let name = "Microsoft.Extensions.DependencyInjection.AuthorizationServiceCollectionExtensions, " +
"Microsoft.AspNetCore.Authorization, Version=2.1"
let ``type`` = Type.GetType name
//let private addAuthorization = ``type``.GetMethod("AddAuthorization", BindingFlags.Public ||| BindingFlags.Static,
[| typeof<IServiceCollection>; typeof<Action<AuthorizationOptions>> |])
let addAuthorization = ``type``.GetMethods().[1]
let configure = Action<AuthorizationOptions>(configure)
addAuthorization.Invoke(null, [| services; configure |]) |> ignore
services
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment