Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 public WidgetPackageFinder(ILogger logger, WidgetOptions options)
 {
     Logger  = logger;
     Options = options;
 }
Ejemplo n.º 3
0
 public WidgetsManager(IWidgetFactory widgetApplication, WidgetOptions options)
 {
     _widgetApplication = widgetApplication;
     _options           = options;
 }
Ejemplo n.º 4
0
 public WidgetsManager(IWidgetFactory widgetApplication, IOptions <WidgetOptions> options)
 {
     _widgetApplication = widgetApplication;
     _options           = options.Value;
 }
Ejemplo n.º 5
0
        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());
        }