public void Release(WidgetViewContext context, object viewComponent)
 {
     if (viewComponent is IDisposable disposable)
     {
         disposable.Dispose();
     }
 }
Esempio n. 2
0
        private async Task InvokeCoreAsync(WidgetViewContext context)
        {
            var executeMethod = context.ComponentDescriptor.MethodInfo;

            var methodReturnType = executeMethod.ReturnType;

            var instance = _widgetComponentActivator.Create(context) as WidgetComponent;

            instance.WidgetViewContext = context;

            IWidgetComponentViewResult result = null;

            if (methodReturnType == typeof(Task <IWidgetComponentViewResult>))
            {
                result = await MethodExecute <Task <IWidgetComponentViewResult> >(executeMethod, instance, null);
            }
            else if (methodReturnType == typeof(Task <string>))
            {
                result = new ContentWidgetViewResult(await MethodExecute <Task <string> >(executeMethod, instance, null));
            }
            else if (methodReturnType == typeof(IWidgetComponentViewResult))
            {
                result = MethodExecute <IWidgetComponentViewResult>(executeMethod, instance, null);
            }
            else
            {
                throw new Exception("Unsupport.");
            }

            await result.ExecuteAsync(context);
        }
        public Task ExecuteAsync(WidgetViewContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.HtmlEncoder.Encode(context.Writer, Content);

            return(Task.CompletedTask);
        }
        public object Create(WidgetViewContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var componentType = context.ComponentDescriptor.TypeInfo;

            if (componentType == null)
            {
                throw new ArgumentNullException(nameof(context.ComponentDescriptor.TypeInfo));
            }

            var viewComponent = _typeActivatorCache.CreateInstance <object>(
                context.ViewContext.HttpContext.RequestServices,
                context.ComponentDescriptor.TypeInfo.AsType());

            return(viewComponent);
        }
Esempio n. 5
0
 public async Task InvokeAsync(WidgetViewContext context)
 {
     await InvokeCoreAsync(context);
 }