internal static QueryDelegate CreateDelegate <TMiddleware>(
            Func <IServiceProvider, QueryDelegate, TMiddleware> factory,
            QueryDelegate next)
            where TMiddleware : class
        {
            object      sync       = new object();
            TMiddleware middleware = null;

            var compiled = MiddlewareActivator
                           .CompileMiddleware <TMiddleware, IQueryContext>();

            return(context =>
            {
                if (middleware == null)
                {
                    lock (sync)
                    {
                        if (middleware == null)
                        {
                            middleware = factory(context.Services, next);
                        }
                    }
                }

                return compiled(context, context.Services, middleware);
            });
        }
Exemple #2
0
        private static FieldDelegate CreateDelegate <TMiddleware>(
            Func <IServiceProvider, FieldDelegate, TMiddleware> factory,
            FieldDelegate next)
            where TMiddleware : class
        {
            object      sync       = new object();
            TMiddleware middleware = null;

            ClassQueryDelegate <TMiddleware, IMiddlewareContext> compiled =
                MiddlewareActivator
                .CompileMiddleware <TMiddleware, IMiddlewareContext>();

            return(context =>
            {
                if (middleware == null)
                {
                    lock (sync)
                    {
                        if (middleware == null)
                        {
                            middleware = factory(
                                context.Service <IServiceProvider>(),
                                next);
                        }
                    }
                }

                return compiled(
                    context,
                    context.Service <IServiceProvider>(),
                    middleware);
            });
        }