dimanche 11 février 2018

Overhead for Late binding actions call after initial reflection

I'm writing a framework which aids in making rest dynamic. I have a factory which build my rest services, after the factory is built I need to register events for my websockets.

I do not have my concrete hubtype at compile time so I'm using reflection to create an action to invoke my Generic Method.

static Action<IServiceProvider, IAsyncCRUDService<TDTO>> DynamicallyRegisterHubEvents<TDTO>(Type hubType)
{
    var registerServiceMethod = RegisterHubEventsMethodInfo.MakeGenericMethod(typeof(TDTO), hubType);

    return (IServiceProvider services, IAsyncCRUDService<TDTO> restService) =>
    {
        var parameters = new object[] { services, restService };
        registerServiceMethod.Invoke(null, parameters);
    };
}

The result of this action will be used inside of the factory which creates my service.

We all know reflection is slow.

But since, I've abstracted the reflection portion outside of the action, my method info will be captured with a closure. Will this still be slow? Or Is there a more efficient to do this?





Aucun commentaire:

Enregistrer un commentaire