async Task <object> GetModelAsync(KasbahWebContext context, object properties, ComponentDefinition component, IPresentable content)
        {
            using (MiniProfiler.Current.Step(nameof(GetModelAsync)))
            {
                var asyncMethod = component.Control.GetMethod(nameof(ComponentBase <object> .GetModelAsync));
                if (asyncMethod == null)
                {
                    return(null);
                }

                dynamic instance = ActivatorUtilities.CreateInstance(_serviceProvider, component.Control);
                try
                {
                    var task = (Task)asyncMethod.Invoke(instance, new object[] { context, properties, content });

                    await task.ConfigureAwait(false);

                    return((object)((dynamic)task).Result);
                }
                finally
                {
                    if (instance is IDisposable disposable)
                    {
                        disposable.Dispose();
                    }
                }
            }
        }
示例#2
0
        public async Task Invoke(HttpContext context)
        {
            var kasbahWebContext = new KasbahWebContext
            {
                WebApplication = _kasbahWebApplication,
                HttpContext    = context,
                ContentService = _contentService,
                TypeRegistry   = _typeRegistry,
                TypeMapper     = _typeMapper,
                SiteRegistry   = _siteRegistry
            };

            context.Items[KasbahWebContext.Key] = kasbahWebContext;

            await _next.Invoke(context);
        }
示例#3
0
 public virtual object GetModel(KasbahWebContext context)
 {
     return(null);
 }
 public virtual Task <TModel> GetModelAsync(KasbahWebContext context, TModel model, IPresentable content)
 => Task.FromResult(model);
示例#5
0
 public virtual Task <TModel> GetModelAsync(KasbahWebContext context, TProperties properties, IPresentable content)
 => Task.FromResult(default(TModel));