public WidgetFactory(IServiceCollection services, WidgetOptions widgetOptions)
        {
            Services      = services;
            WidgetOptions = widgetOptions;

            Logger = services.BuildServiceProvider().GetRequiredService <ILogger <WidgetFactory> >();

            Widgets = LoadWidgets(services, widgetOptions);

            services.AddSingleton <IWidgetFactory>(this);
            services.AddSingleton <IWidgetContainer>(this);

            services.AddSingleton <ITypeActivatorCache, TypeActivatorCache>();
            services.AddSingleton <IApplicationWidgetPartManager, ApplicationWidgetPartManager>();

            var manager = new WidgetsManager(this, widgetOptions);

            services.AddSingleton <IWidgetsManager>((_) =>
            {
                var logger = _.GetRequiredService <ILogger <WidgetFactory> >();
                logger.LogInformation("Init WidgetsManager");
                return(manager);
            });

            services.AddScoped <IWidgetViewInvoker, WidgetViewInvoker>();
            services.AddScoped <IWidgetComponentFactory, WidgetComponentFactory>();
            services.AddScoped <IWidgetComponentActivator, WidgetComponentActivator>();
            services.AddScoped <IWidgetViewLocationExpander, DefaultWidgetViewLocationExpander>();
            services.AddScoped <IWidgetViewLocationResolveService, WidgetViewLocationResolveService>();

            ConfigServices(services);
            RegisterWidgets(services, manager);
        }
示例#2
0
 public WidgetPackageFinder(ILogger logger, WidgetOptions options)
 {
     Logger  = logger;
     Options = options;
 }
示例#3
0
 public WidgetsManager(IWidgetFactory widgetApplication, WidgetOptions options)
 {
     _widgetApplication = widgetApplication;
     _options           = options;
 }
示例#4
0
 public WidgetsManager(IWidgetFactory widgetApplication, IOptions <WidgetOptions> options)
 {
     _widgetApplication = widgetApplication;
     _options           = options.Value;
 }
        private IReadOnlyList <WidgetDescriptor> LoadWidgets(IServiceCollection services, WidgetOptions options)
        {
            var hostEnvironment = services.GetSingletonInstance <IHostEnvironment>();
            var finder          = new WidgetPackageFinder(Logger, options);

            return(finder.Load(options.Directory ?? "widgets").ToList());
        }