public SmartApplicationContext(
            IHostEnvironment hostEnvironment,
            IConfiguration configuration,
            ILogger logger,
            params Assembly[] coreAssemblies)
        {
            Guard.NotNull(hostEnvironment, nameof(hostEnvironment));
            Guard.NotNull(configuration, nameof(configuration));
            Guard.NotNull(logger, nameof(logger));

            HostEnvironment = hostEnvironment;
            Configuration   = configuration;
            Logger          = logger;

            ConfigureFileSystem(hostEnvironment);

            DataSettings.SetApplicationContext(this, OnDataSettingsLoaded);

            ModuleCatalog = new ModuleCatalog();
            TypeScanner   = new DefaultTypeScanner(ModuleCatalog, logger, coreAssemblies);
            OSIdentity    = new GenericOSIdentity();

            // Create app configuration
            // TODO: (core) Try to incorporate IOptionsMonitor<SmartConfiguration> somehow.
            var config = new SmartConfiguration();

            configuration.Bind("Smartstore", config);

            AppConfiguration = config;
        }
Exemplo n.º 2
0
        public static IEngine Create(SmartConfiguration configuration)
        {
            if (Singleton <IEngine> .Instance == null)
            {
                Singleton <IEngine> .Instance = CreateEngineInstance(configuration);
            }

            return(Singleton <IEngine> .Instance);
        }
Exemplo n.º 3
0
        private static IEngine CreateEngineInstance(SmartConfiguration configuration)
        {
            var engineTypeSetting = configuration.EngineType;

            if (engineTypeSetting.HasValue())
            {
                var engineType = Type.GetType(engineTypeSetting);

                if (engineType == null)
                {
                    throw new ApplicationException($"The type '${engineType}' could not be found. Please check the configuration at 'appSettings.Smart.EngineType' or check for missing assemblies.");
                }

                if (!typeof(IEngine).IsAssignableFrom(engineType))
                {
                    throw new ApplicationException($"The type '${engineType}' does not implement '${typeof(IEngine).FullName}' and cannot be configured in 'appSettings.Smart.EngineType' for that purpose.");
                }

                return(Activator.CreateInstance(engineType) as IEngine);
            }

            return(new SmartEngine());
        }