Exemple #1
0
 public LocalizationService(ICacheManager cacheManager, LConfig config, IWebHelper webHelper)
 {
     this._cacheManager = cacheManager;
     this._config       = config;
     this._webHelper    = webHelper;
     this._xmlPath      = this._webHelper.MapPath(this._config.LanguagePath);
 }
Exemple #2
0
        protected virtual void RegisterDependencies(LConfig config)
        {
            var builder   = new ContainerBuilder();
            var container = builder.Build();

            //dependencies
            var typeFinder = new WebAppTypeFinder(config);

            builder = new ContainerBuilder();
            builder.RegisterInstance(config).As <LConfig>().SingleInstance();
            builder.RegisterType <LocalizationService>().As <ILocalizationService>().SingleInstance();
            builder.RegisterType <SettingService>().As <ISettingService>().SingleInstance();
            builder.RegisterGeneric(typeof(Repository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();
            builder.RegisterType <RepositoryContext>().As <IRepositoryContext>().InstancePerLifetimeScope();

            //web helper
            builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope();

            //plugins
            builder.RegisterType <PluginFinder>().As <IPluginFinder>().InstancePerLifetimeScope();

            //cache manager
            builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().Named <ICacheManager>("lcl_cache_static").SingleInstance();
            builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().Named <ICacheManager>("lcl_cache_per_request").InstancePerLifetimeScope();

            //event bus
            builder.RegisterType <EventBus>().As <IEventBus>().InstancePerLifetimeScope();

            builder.RegisterType <EventAggregator>().As <IEventAggregator>().InstancePerLifetimeScope();
            builder.RegisterType <DomainEvent>().As <IDomainEvent>().InstancePerLifetimeScope();



            builder.RegisterInstance(this).As <IEngine>().SingleInstance();
            builder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance();
            builder.Update(container);

            //register dependencies provided by other assemblies
            builder = new ContainerBuilder();
            var drTypes     = typeFinder.FindClassesOfType <IDependencyRegistrar>();
            var drInstances = new List <IDependencyRegistrar>();

            foreach (var drType in drTypes)
            {
                drInstances.Add((IDependencyRegistrar)Activator.CreateInstance(drType));
            }
            //sort
            drInstances = drInstances.AsQueryable().OrderBy(t => t.Order).ToList();
            foreach (var dependencyRegistrar in drInstances)
            {
                dependencyRegistrar.Register(builder, typeFinder);
            }
            builder.Update(container);

            this._containerManager = new ContainerManager(container);

            //set dependency resolver
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Exemple #3
0
        public void Initialize(LConfig config)
        {
            Logger.LogInfo("LCL Initialize components and plugins in the nop environment. ");
            //register dependencies
            RegisterDependencies(config);

            //startup tasks
            if (!config.IgnoreStartupTasks)
            {
                RunStartupTasks();
            }
        }
Exemple #4
0
        protected static IEngine CreateEngineInstance(LConfig config)
        {
            if (config != null && !string.IsNullOrEmpty(config.EngineType))
            {
                var engineType = Type.GetType(config.EngineType);
                if (engineType == null)
                {
                    throw new ConfigurationErrorsException("The type '" + config.EngineType + "' could not be found. Please check the configuration at /configuration/nop/engine[@engineType] or check for missing assemblies.");
                }
                if (!typeof(IEngine).IsAssignableFrom(engineType))
                {
                    throw new ConfigurationErrorsException("The type '" + engineType + "' doesn't implement 'LCL.Core.Infrastructure.IEngine' and cannot be configured in /configuration/nop/engine[@engineType] for that purpose.");
                }
                return(Activator.CreateInstance(engineType) as IEngine);
            }

            return(new LEngine());
        }
Exemple #5
0
        public void Initialize(LConfig config)
        {
            try
            {
                Logger.LogInfo("LCL Initialize components and plugins in the nop environment. ");
                //register dependencies
                RegisterDependencies(config);

                //startup tasks
                if (!config.IgnoreStartupTasks)
                {
                    RunStartupTasks();
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message, ex);
            }
        }
Exemple #6
0
        protected virtual void RegisterDependencies(LConfig config)
        {
            var builder   = new ContainerBuilder();
            var container = builder.Build();

            //dependencies
            var typeFinder = new WebAppTypeFinder(config);

            builder = new ContainerBuilder();
            builder.RegisterInstance(config).As <LConfig>().SingleInstance();
            builder.RegisterInstance(this).As <IEngine>().SingleInstance();
            builder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance();

            // DDD
            builder.RegisterGeneric(typeof(Repository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(Repository <,>)).As(typeof(IRepository <,>)).InstancePerLifetimeScope();
            builder.RegisterType <RepositoryContext>().As <IRepositoryContext>().InstancePerLifetimeScope();

            builder.RegisterType <EventBus>().As <IEventBus>().InstancePerLifetimeScope();
            builder.RegisterType <EventAggregator>().As <IEventAggregator>().InstancePerLifetimeScope();
            builder.RegisterType <DomainEvent>().As <IDomainEvent>().InstancePerLifetimeScope();

            //plugins
            builder.RegisterType <PluginFinder>().As <IPluginFinder>().InstancePerLifetimeScope();

            //cache manager
            builder.RegisterType <MemoryCacheProvider>().As <ICacheProvider>().Named <ICacheProvider>("lcl_cache_static").SingleInstance();
            //config
            builder.RegisterType <DictionaryBasedConfig>().As <IDictionaryBasedConfig>().InstancePerLifetimeScope();
            builder.RegisterType <ModuleConfigurations>().As <IModuleConfigurations>().InstancePerLifetimeScope();
            builder.RegisterType <LclStartupConfiguration>().As <ILclStartupConfiguration>().InstancePerLifetimeScope();

            builder.RegisterType <LocalizationService>().As <ILocalizationService>().SingleInstance();
            builder.RegisterType <SettingService>().As <ISettingService>().SingleInstance();
            builder.RegisterType <SequentialGuidGenerator>().As <IGuidGenerator>().InstancePerLifetimeScope();


            builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies())
            .Where(t => t.GetCustomAttribute <DependencyRegisterAttribute>() != null)
            .AsImplementedInterfaces()
            .InstancePerRequest();

            builder.Update(container);

            //register dependencies provided by other assemblies
            builder = new ContainerBuilder();
            var drTypes     = typeFinder.FindClassesOfType <IDependencyRegistrar>();
            var drInstances = new List <IDependencyRegistrar>();

            foreach (var drType in drTypes)
            {
                drInstances.Add((IDependencyRegistrar)Activator.CreateInstance(drType));
            }
            //sort
            drInstances = drInstances.AsQueryable().OrderBy(t => t.Order).ToList();
            foreach (var dependencyRegistrar in drInstances)
            {
                dependencyRegistrar.Register(builder, typeFinder);
            }
            builder.Update(container);

            this._containerManager = new ContainerManager(container);
        }
 public WebAppTypeFinder(LConfig config)
 {
     this._ensureBinFolderAssembliesLoaded = config.DynamicDiscovery;
 }
Exemple #8
0
 static void Main(string[] args)
 {
     AppDomain.CurrentDomain.UnhandledException += Program_UnhandledException;
     if (args.Contains("-v") || args.Contains("-verbose"))
     {
         LConfig = new LoggerConfiguration()
                   .MinimumLevel.Verbose()
                   .Enrich.FromLogContext()
                   .WriteTo.LiterateConsole();
     }
     else
     {
         LConfig = new LoggerConfiguration()
                   .MinimumLevel.Debug()
                   .Enrich.FromLogContext()
                   .WriteTo.LiterateConsole();
     }
     Log.Logger = LConfig.CreateLogger();
     L          = new PhylLogger <Program>();
     ParserResult <object> result = Parser.Default.ParseArguments <DumpOptions, GraphOptions>(args)
                                    .WithNotParsed((IEnumerable <Error> errors) =>
     {
         L.Info("The command-line options had the following errors: {errors}", errors.Select(e => e.Tag));
         Exit(ExitResult.INVALID_OPTIONS);
     })
                                    .WithParsed((Options o) =>
     {
         if (o.MaxConcurrencyLevel < 1 || o.MaxConcurrencyLevel > 128)
         {
             L.Error("The max concurrency level option must be between 1 and 128");
             Exit(ExitResult.INVALID_OPTIONS);
         }
         foreach (PropertyInfo prop in o.GetType().GetProperties())
         {
             EngineOptions.Add(prop.Name, prop.GetValue(o));
         }
     })
                                    .WithParsed((DumpOptions o) =>
     {
         if (!AnalysisEngine.DumpInformationCategories.Contains(o.Information))
         {
             L.Info("The available information categories and structures are: {categories}.", AnalysisEngine.DumpInformationCategories);
             Exit(ExitResult.INVALID_OPTIONS);
         }
         else if (string.IsNullOrEmpty(o.OutputFile))
         {
             L.Error("You must specify a file name or file name prefix to dump {0} information to.", o.Information);
             Exit(ExitResult.INVALID_OPTIONS);
         }
         else
         {
             EngineOptions.Add("OperationType", AnalysisEngine.OperationType.DUMP);
             Analyze();
         }
     })
                                    .WithParsed((GraphOptions o) =>
     {
         if (!AnalysisEngine.GraphInformationCategories.Contains(o.Information))
         {
             L.Info("The available information categories and structures for graphing are: {categories}.", AnalysisEngine.GraphInformationCategories);
             Exit(ExitResult.INVALID_OPTIONS);
         }
         else
         {
             EngineOptions.Add("OperationType", AnalysisEngine.OperationType.GRAPH);
             Analyze();
         }
     });
 }