Ejemplo n.º 1
0
        /// <summary>
        /// Register dependencies using Autofac
        /// </summary>
        /// <param name="nopConfig">Startup GS configuration parameters</param>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="typeFinder">Type finder</param>
        protected virtual IServiceProvider RegisterDependencies(GSConfig nopConfig, IServiceCollection services, ITypeFinder typeFinder)
        {
            var containerBuilder = new ContainerBuilder();

            //register engine
            containerBuilder.RegisterInstance(this).As <IEngine>().SingleInstance();

            //register type finder
            containerBuilder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance();

            //find dependency registrars provided by other assemblies
            var dependencyRegistrars = typeFinder.FindClassesOfType <IDependencyRegistrar>();

            //create and sort instances of dependency registrars
            var instances = dependencyRegistrars
                            //.Where(dependencyRegistrar => PluginManager.FindPlugin(dependencyRegistrar)?.Installed ?? true) //ignore not installed plugins
                            .Select(dependencyRegistrar => (IDependencyRegistrar)Activator.CreateInstance(dependencyRegistrar))
                            .OrderBy(dependencyRegistrar => dependencyRegistrar.Order);

            //register all provided dependencies
            foreach (var dependencyRegistrar in instances)
            {
                dependencyRegistrar.Register(containerBuilder, typeFinder, nopConfig);
            }

            //populate Autofac container builder with the set of registered service descriptors
            containerBuilder.Populate(services);

            //create service provider
            _serviceProvider = new AutofacServiceProvider(containerBuilder.Build());
            return(_serviceProvider);
        }
Ejemplo n.º 2
0
 public WorksController(IWorkTaskService workTaskService,
                        IContractLogService contractLogService,
                        CurrencySettings currencySettings,
                        ICurrencyService currencyService,
                        IWorkModelFactory workModelFactory,
                        ILocalizationService localizationService,
                        IPermissionService permissionService,
                        IWorkContext workContext,
                        ITaskModelFactory taskModelFactory,
                        IContractModelFactory contractModelFactory,
                        IContractService contractService,
                        GSConfig config,
                        IDataProvider dataProvider,
                        IProcuringAgencyService procuringAgencyService,
                        IDbContext dbContext,
                        IPriceFormatter priceFormatter
                        )
 {
     this._workModelFactory     = workModelFactory;
     this._contractLogService   = contractLogService;
     this._currencySettings     = currencySettings;
     this._localizationService  = localizationService;
     this._workTaskService      = workTaskService;
     this._permissionService    = permissionService;
     this._workContext          = workContext;
     this._taskModelFactory     = taskModelFactory;
     this._contractModelFactory = contractModelFactory;
     this._contractService      = contractService;
     this._currencyService      = currencyService;
     this._config                 = config;
     this._dataProvider           = dataProvider;
     this._procuringAgencyService = procuringAgencyService;
     this._dbContext              = dbContext;
     this._priceFormatter         = priceFormatter;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Register the plugin definition
        /// </summary>
        /// <param name="config">Config</param>
        /// <param name="applicationPartManager">Application part manager</param>
        /// <param name="plug">Plugin file info</param>
        /// <returns>Assembly</returns>
        private static Assembly RegisterPluginDefinition(GSConfig config, ApplicationPartManager applicationPartManager, string plug)
        {
            //we can now register the plugin definition
            Assembly pluginAssembly;

            try
            {
                pluginAssembly = Assembly.LoadFrom(plug);
            }
            catch (FileLoadException)
            {
                if (config.UseUnsafeLoadAssembly)
                {
                    //if an application has been copied from the web, it is flagged by Windows as being a web application,
                    //even if it resides on the local computer.You can change that designation by changing the file properties,
                    //or you can use the<loadFromRemoteSources> element to grant the assembly full trust.As an alternative,
                    //you can use the UnsafeLoadFrom method to load a local assembly that the operating system has flagged as
                    //having been loaded from the web.
                    //see http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
                    pluginAssembly = Assembly.UnsafeLoadFrom(plug);
                }
                else
                {
                    throw;
                }
            }

            Debug.WriteLine("Adding to ApplicationParts: '{0}'", pluginAssembly.FullName);
            applicationPartManager.ApplicationParts.Add(new AssemblyPart(pluginAssembly));

            return(pluginAssembly);
        }
Ejemplo n.º 4
0
 public UserAgentHelper(IHttpContextAccessor httpContextAccessor,
                        IGSFileProvider fileProvider,
                        GSConfig nopConfig)
 {
     this._httpContextAccessor = httpContextAccessor;
     this._fileProvider        = fileProvider;
     this._nopConfig           = nopConfig;
 }
Ejemplo n.º 5
0
        public void ReportStateToCS(NetSessionBase session)
        {
            Protos.GS2CS_ReportState reportState = ProtoCreator.Q_GS2CS_ReportState();
            GSConfig config = GS.instance.config;

            reportState.GsInfo = new Protos.GSInfo
            {
                Id       = config.gsID,
                Name     = config.name,
                Ip       = config.externalIP,
                Port     = config.externalPort,
                Password = config.password,
                State    = (Protos.GSInfo.Types.State)GS.instance.state
            };
            session.Send(reportState);
        }
Ejemplo n.º 6
0
        public RedisCacheManager(ICacheManager perRequestCacheManager,
                                 IRedisConnectionWrapper connectionWrapper,
                                 GSConfig config)
        {
            if (string.IsNullOrEmpty(config.RedisCachingConnectionString))
            {
                throw new Exception("Redis connection string is empty");
            }

            this._perRequestCacheManager = perRequestCacheManager;

            // ConnectionMultiplexer.Connect should only be called once and shared between callers
            this._connectionWrapper = connectionWrapper;

            this._db = _connectionWrapper.GetDatabase();
        }
Ejemplo n.º 7
0
        public AzurePictureService(IDataProvider dataProvider,
                                   IDbContext dbContext,
                                   IEventPublisher eventPublisher,
                                   IGSFileProvider fileProvider,
                                   IRepository <Picture> pictureRepository,
                                   IRepository <PictureBinary> pictureBinaryRepository,
                                   //IRepository<ContractPicture> contractPictureRepository,
                                   ISettingService settingService,
                                   IStaticCacheManager cacheManager,
                                   IUrlRecordService urlRecordService,
                                   IWebHelper webHelper,
                                   MediaSettings mediaSettings,
                                   GSConfig config)
            : base(dataProvider,
                   dbContext,
                   eventPublisher,
                   fileProvider,
                   pictureRepository,
                   pictureBinaryRepository,
                   //contractPictureRepository,
                   settingService,
                   urlRecordService,
                   webHelper,
                   mediaSettings)
        {
            this._cacheManager  = cacheManager;
            this._mediaSettings = mediaSettings;
            this._config        = config;

            if (string.IsNullOrEmpty(_config.AzureBlobStorageConnectionString))
            {
                throw new Exception("Azure connection string for BLOB is not specified");
            }

            if (string.IsNullOrEmpty(_config.AzureBlobStorageContainerName))
            {
                throw new Exception("Azure container name for BLOB is not specified");
            }

            if (string.IsNullOrEmpty(_config.AzureBlobStorageEndPoint))
            {
                throw new Exception("Azure end point for BLOB is not specified");
            }

            CreateCloudBlobContainer();
        }
Ejemplo n.º 8
0
 public TaskModelFactory(ICurrencyService currencyService,
                         ITaskGroupService taskGroupService,
                         ICountryService countryService,
                         ILocalizationService localizationService,
                         IStateProvinceService stateProvinceService,
                         IStaticCacheManager cacheManager,
                         IWorkContext workContext,
                         IWorkTaskService workTaskService,
                         ICustomerService customerService,
                         IContractService contractService,
                         IContractPaymentService contractPaymentService,
                         IContractLogService contractLogService,
                         IUnitService unitService,
                         IPictureService pictureService,
                         MediaSettings mediaSettings,
                         IPriceFormatter priceFormatter,
                         IGenericAttributeService genericAttributeService,
                         IContractTypeService contractTypeService,
                         GSConfig config)
 {
     this._currencyService         = currencyService;
     this._taskGroupService        = taskGroupService;
     this._countryService          = countryService;
     this._localizationService     = localizationService;
     this._stateProvinceService    = stateProvinceService;
     this._cacheManager            = cacheManager;
     this._workContext             = workContext;
     this._workTaskService         = workTaskService;
     this._customerService         = customerService;
     this._contractPaymentService  = contractPaymentService;
     this._contractService         = contractService;
     this._contractLogService      = contractLogService;
     this._unitService             = unitService;
     this._pictureService          = pictureService;
     this._mediaSettings           = mediaSettings;
     this._genericAttributeService = genericAttributeService;
     this._priceFormatter          = priceFormatter;
     this._contractTypeService     = contractTypeService;
     this._config = config;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Initialize
        /// </summary>
        /// <param name="applicationPartManager">Application part manager</param>
        /// <param name="config">Config</param>
        public static void Initialize(ApplicationPartManager applicationPartManager, GSConfig config)
        {
            if (applicationPartManager == null)
            {
                throw new ArgumentNullException(nameof(applicationPartManager));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            using (new WriteLockDisposable(Locker))
            {
                // TODO: Add verbose exception handling / raising here since this is happening on app startup and could
                // prevent app from starting altogether
                var pluginFolder = _fileProvider.MapPath(GSPluginDefaults.Path);
                _shadowCopyFolder        = _fileProvider.MapPath(GSPluginDefaults.ShadowCopyPath);
                _reserveShadowCopyFolder = _fileProvider.Combine(_fileProvider.MapPath(GSPluginDefaults.ShadowCopyPath), $"{GSPluginDefaults.ReserveShadowCopyPathName}{DateTime.Now.ToFileTimeUtc()}");

                var referencedPlugins   = new List <PluginDescriptor>();
                var incompatiblePlugins = new List <string>();

                try
                {
                    var installedPluginSystemNames = GetInstalledPluginNames(_fileProvider.MapPath(GSPluginDefaults.InstalledPluginsFilePath));

                    Debug.WriteLine("Creating shadow copy folder and querying for DLLs");
                    //ensure folders are created
                    _fileProvider.CreateDirectory(pluginFolder);
                    _fileProvider.CreateDirectory(_shadowCopyFolder);

                    //get list of all files in bin
                    var binFiles = _fileProvider.GetFiles(_shadowCopyFolder, "*", false);
                    if (config.ClearPluginShadowDirectoryOnStartup)
                    {
                        //clear out shadow copied plugins
                        foreach (var f in binFiles)
                        {
                            if (_fileProvider.GetFileName(f).Equals("placeholder.txt", StringComparison.InvariantCultureIgnoreCase))
                            {
                                continue;
                            }

                            Debug.WriteLine("Deleting " + f);
                            try
                            {
                                //ignore index.htm
                                var fileName = _fileProvider.GetFileName(f);
                                if (fileName.Equals("index.htm", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    continue;
                                }

                                _fileProvider.DeleteFile(f);
                            }
                            catch (Exception exc)
                            {
                                Debug.WriteLine("Error deleting file " + f + ". Exception: " + exc);
                            }
                        }

                        //delete all reserve folders
                        foreach (var directory in _fileProvider.GetDirectories(_shadowCopyFolder, GSPluginDefaults.ReserveShadowCopyPathNamePattern))
                        {
                            try
                            {
                                _fileProvider.DeleteDirectory(directory);
                            }
                            catch
                            {
                                //do nothing
                            }
                        }
                    }

                    //load description files
                    foreach (var dfd in GetDescriptionFilesAndDescriptors(pluginFolder))
                    {
                        var descriptionFile  = dfd.Key;
                        var pluginDescriptor = dfd.Value;

                        //ensure that version of plugin is valid
                        if (!pluginDescriptor.SupportedVersions.Contains(GSVersion.CurrentVersion, StringComparer.InvariantCultureIgnoreCase))
                        {
                            incompatiblePlugins.Add(pluginDescriptor.SystemName);
                            continue;
                        }

                        //some validation
                        if (string.IsNullOrWhiteSpace(pluginDescriptor.SystemName))
                        {
                            throw new Exception($"A plugin '{descriptionFile}' has no system name. Try assigning the plugin a unique name and recompiling.");
                        }
                        if (referencedPlugins.Contains(pluginDescriptor))
                        {
                            throw new Exception($"A plugin with '{pluginDescriptor.SystemName}' system name is already defined");
                        }

                        //set 'Installed' property
                        pluginDescriptor.Installed = installedPluginSystemNames
                                                     .FirstOrDefault(x => x.Equals(pluginDescriptor.SystemName, StringComparison.InvariantCultureIgnoreCase)) != null;

                        try
                        {
                            var directoryName = _fileProvider.GetDirectoryName(descriptionFile);
                            if (string.IsNullOrEmpty(directoryName))
                            {
                                throw new Exception($"Directory cannot be resolved for '{_fileProvider.GetFileName(descriptionFile)}' description file");
                            }

                            //get list of all DLLs in plugins (not in bin!)
                            var pluginFiles = _fileProvider.GetFiles(directoryName, "*.dll", false)
                                              //just make sure we're not registering shadow copied plugins
                                              .Where(x => !binFiles.Select(q => q).Contains(x))
                                              .Where(x => IsPackagePluginFolder(_fileProvider.GetDirectoryName(x)))
                                              .ToList();

                            //other plugin description info
                            var mainPluginFile = pluginFiles
                                                 .FirstOrDefault(x => _fileProvider.GetFileName(x).Equals(pluginDescriptor.AssemblyFileName, StringComparison.InvariantCultureIgnoreCase));

                            //plugin have wrong directory
                            if (mainPluginFile == null)
                            {
                                incompatiblePlugins.Add(pluginDescriptor.SystemName);
                                continue;
                            }

                            pluginDescriptor.OriginalAssemblyFile = mainPluginFile;

                            //shadow copy main plugin file
                            pluginDescriptor.ReferencedAssembly = PerformFileDeploy(mainPluginFile, applicationPartManager, config);

                            //load all other referenced assemblies now
                            foreach (var plugin in pluginFiles
                                     .Where(x => !_fileProvider.GetFileName(x).Equals(_fileProvider.GetFileName(mainPluginFile), StringComparison.InvariantCultureIgnoreCase))
                                     .Where(x => !IsAlreadyLoaded(x)))
                            {
                                PerformFileDeploy(plugin, applicationPartManager, config);
                            }

                            //init plugin type (only one plugin per assembly is allowed)
                            foreach (var t in pluginDescriptor.ReferencedAssembly.GetTypes())
                            {
                                if (typeof(IPlugin).IsAssignableFrom(t))
                                {
                                    if (!t.IsInterface)
                                    {
                                        if (t.IsClass && !t.IsAbstract)
                                        {
                                            pluginDescriptor.PluginType = t;
                                            break;
                                        }
                                    }
                                }
                            }

                            referencedPlugins.Add(pluginDescriptor);
                        }
                        catch (ReflectionTypeLoadException ex)
                        {
                            //add a plugin name. this way we can easily identify a problematic plugin
                            var msg = $"Plugin '{pluginDescriptor.FriendlyName}'. ";
                            foreach (var e in ex.LoaderExceptions)
                            {
                                msg += e.Message + Environment.NewLine;
                            }

                            var fail = new Exception(msg, ex);
                            throw fail;
                        }
                        catch (Exception ex)
                        {
                            //add a plugin name. this way we can easily identify a problematic plugin
                            var msg = $"Plugin '{pluginDescriptor.FriendlyName}'. {ex.Message}";

                            var fail = new Exception(msg, ex);
                            throw fail;
                        }
                    }
                }
                catch (Exception ex)
                {
                    var msg = string.Empty;
                    for (var e = ex; e != null; e = e.InnerException)
                    {
                        msg += e.Message + Environment.NewLine;
                    }

                    var fail = new Exception(msg, ex);
                    throw fail;
                }

                ReferencedPlugins   = referencedPlugins;
                IncompatiblePlugins = incompatiblePlugins;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Perform file deploy
        /// </summary>
        /// <param name="plug">Plugin file info</param>
        /// <param name="applicationPartManager">Application part manager</param>
        /// <param name="config">Config</param>
        /// <param name="shadowCopyPath">Shadow copy path</param>
        /// <returns>Assembly</returns>
        private static Assembly PerformFileDeploy(string plug, ApplicationPartManager applicationPartManager, GSConfig config, string shadowCopyPath = "")
        {
            var parent = string.IsNullOrEmpty(plug) ? string.Empty : _fileProvider.GetParentDirectory(plug);

            if (string.IsNullOrEmpty(parent))
            {
                throw new InvalidOperationException($"The plugin directory for the {_fileProvider.GetFileName(plug)} file exists in a folder outside of the allowed nopCommerce folder hierarchy");
            }

            if (!config.UsePluginsShadowCopy)
            {
                return(RegisterPluginDefinition(config, applicationPartManager, plug));
            }

            //in order to avoid possible issues we still copy libraries into ~/Plugins/bin/ directory
            if (string.IsNullOrEmpty(shadowCopyPath))
            {
                shadowCopyPath = _shadowCopyFolder;
            }

            _fileProvider.CreateDirectory(shadowCopyPath);
            var shadowCopiedPlug = ShadowCopyFile(plug, shadowCopyPath);

            Assembly shadowCopiedAssembly = null;

            try
            {
                shadowCopiedAssembly = RegisterPluginDefinition(config, applicationPartManager, shadowCopiedPlug);
            }
            catch (FileLoadException)
            {
                if (!config.CopyLockedPluginAssembilesToSubdirectoriesOnStartup || !shadowCopyPath.Equals(_shadowCopyFolder))
                {
                    throw;
                }
            }

            return(shadowCopiedAssembly ?? PerformFileDeploy(plug, applicationPartManager, config, _reserveShadowCopyFolder));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, GSConfig config)
        {
            //file provider
            builder.RegisterType <GSFileProvider>().As <IGSFileProvider>().InstancePerLifetimeScope();

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

            //user agent helper
            builder.RegisterType <UserAgentHelper>().As <IUserAgentHelper>().InstancePerLifetimeScope();

            //data layer
            builder.RegisterType <EfDataProviderManager>().As <IDataProviderManager>().InstancePerDependency();
            builder.Register(context => context.Resolve <IDataProviderManager>().DataProvider).As <IDataProvider>().InstancePerDependency();
            builder.Register(context => new GSObjectContext(context.Resolve <DbContextOptions <GSObjectContext> >()))
            .As <IDbContext>().InstancePerLifetimeScope();

            //repositories
            builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();

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

            //cache manager
            builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().InstancePerLifetimeScope();

            //static cache manager
            if (config.RedisCachingEnabled)
            {
                builder.RegisterType <RedisConnectionWrapper>()
                .As <ILocker>()
                .As <IRedisConnectionWrapper>()
                .SingleInstance();
                builder.RegisterType <RedisCacheManager>().As <IStaticCacheManager>().InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <MemoryCacheManager>()
                .As <ILocker>()
                .As <IStaticCacheManager>()
                .SingleInstance();
            }

            //work context
            builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope();

            //store context
            builder.RegisterType <WebStoreContext>().As <IStoreContext>().InstancePerLifetimeScope();

            //services
            builder.RegisterType <CategoryService>().As <ICategoryService>().InstancePerLifetimeScope();
            builder.RegisterType <ManufacturerService>().As <IManufacturerService>().InstancePerLifetimeScope();
            builder.RegisterType <SpecificationAttributeService>().As <ISpecificationAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <CategoryTemplateService>().As <ICategoryTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <ManufacturerTemplateService>().As <IManufacturerTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <TopicTemplateService>().As <ITopicTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <AddressAttributeFormatter>().As <IAddressAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <AddressAttributeParser>().As <IAddressAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <AddressAttributeService>().As <IAddressAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <AddressService>().As <IAddressService>().InstancePerLifetimeScope();
            builder.RegisterType <VendorService>().As <IVendorService>().InstancePerLifetimeScope();
            builder.RegisterType <VendorAttributeFormatter>().As <IVendorAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <VendorAttributeParser>().As <IVendorAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <VendorAttributeService>().As <IVendorAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <SearchTermService>().As <ISearchTermService>().InstancePerLifetimeScope();
            builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <FulltextService>().As <IFulltextService>().InstancePerLifetimeScope();
            builder.RegisterType <MaintenanceService>().As <IMaintenanceService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerAttributeFormatter>().As <ICustomerAttributeFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerAttributeParser>().As <ICustomerAttributeParser>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerAttributeService>().As <ICustomerAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerService>().As <ICustomerService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerRegistrationService>().As <ICustomerRegistrationService>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerReportService>().As <ICustomerReportService>().InstancePerLifetimeScope();
            builder.RegisterType <PermissionService>().As <IPermissionService>().InstancePerLifetimeScope();
            builder.RegisterType <AclService>().As <IAclService>().InstancePerLifetimeScope();
            builder.RegisterType <GeoLookupService>().As <IGeoLookupService>().InstancePerLifetimeScope();
            builder.RegisterType <CountryService>().As <ICountryService>().InstancePerLifetimeScope();
            builder.RegisterType <CurrencyService>().As <ICurrencyService>().InstancePerLifetimeScope();
            builder.RegisterType <MeasureService>().As <IMeasureService>().InstancePerLifetimeScope();
            builder.RegisterType <StateProvinceService>().As <IStateProvinceService>().InstancePerLifetimeScope();
            builder.RegisterType <StoreService>().As <IStoreService>().InstancePerLifetimeScope();
            builder.RegisterType <StoreMappingService>().As <IStoreMappingService>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizationService>().As <ILocalizationService>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizedEntityService>().As <ILocalizedEntityService>().InstancePerLifetimeScope();
            builder.RegisterType <LanguageService>().As <ILanguageService>().InstancePerLifetimeScope();
            builder.RegisterType <DownloadService>().As <IDownloadService>().InstancePerLifetimeScope();
            builder.RegisterType <MessageTemplateService>().As <IMessageTemplateService>().InstancePerLifetimeScope();
            builder.RegisterType <QueuedEmailService>().As <IQueuedEmailService>().InstancePerLifetimeScope();
            builder.RegisterType <NewsLetterSubscriptionService>().As <INewsLetterSubscriptionService>().InstancePerLifetimeScope();
            builder.RegisterType <CampaignService>().As <ICampaignService>().InstancePerLifetimeScope();
            builder.RegisterType <EmailAccountService>().As <IEmailAccountService>().InstancePerLifetimeScope();
            builder.RegisterType <WorkflowMessageService>().As <IWorkflowMessageService>().InstancePerLifetimeScope();
            builder.RegisterType <MessageTokenProvider>().As <IMessageTokenProvider>().InstancePerLifetimeScope();
            builder.RegisterType <Tokenizer>().As <ITokenizer>().InstancePerLifetimeScope();
            builder.RegisterType <EmailSender>().As <IEmailSender>().InstancePerLifetimeScope();
            builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope();
            builder.RegisterType <CookieAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <UrlRecordService>().As <IUrlRecordService>().InstancePerLifetimeScope();
            builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerActivityService>().As <ICustomerActivityService>().InstancePerLifetimeScope();
            builder.RegisterType <ForumService>().As <IForumService>().InstancePerLifetimeScope();
            builder.RegisterType <GdprService>().As <IGdprService>().InstancePerLifetimeScope();
            builder.RegisterType <PollService>().As <IPollService>().InstancePerLifetimeScope();
            builder.RegisterType <BlogService>().As <IBlogService>().InstancePerLifetimeScope();
            builder.RegisterType <WidgetService>().As <IWidgetService>().InstancePerLifetimeScope();
            builder.RegisterType <TopicService>().As <ITopicService>().InstancePerLifetimeScope();
            builder.RegisterType <NewsService>().As <INewsService>().InstancePerLifetimeScope();
            builder.RegisterType <DateTimeHelper>().As <IDateTimeHelper>().InstancePerLifetimeScope();
            builder.RegisterType <SitemapGenerator>().As <ISitemapGenerator>().InstancePerLifetimeScope();
            builder.RegisterType <PageHeadBuilder>().As <IPageHeadBuilder>().InstancePerLifetimeScope();
            builder.RegisterType <ScheduleTaskService>().As <IScheduleTaskService>().InstancePerLifetimeScope();
            builder.RegisterType <ExportManager>().As <IExportManager>().InstancePerLifetimeScope();
            builder.RegisterType <ImportManager>().As <IImportManager>().InstancePerLifetimeScope();
            builder.RegisterType <PdfService>().As <IPdfService>().InstancePerLifetimeScope();
            builder.RegisterType <UploadService>().As <IUploadService>().InstancePerLifetimeScope();
            builder.RegisterType <ThemeProvider>().As <IThemeProvider>().InstancePerLifetimeScope();
            builder.RegisterType <ThemeContext>().As <IThemeContext>().InstancePerLifetimeScope();
            builder.RegisterType <ExternalAuthenticationService>().As <IExternalAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <RoutePublisher>().As <IRoutePublisher>().SingleInstance();
            builder.RegisterType <ReviewTypeService>().As <IReviewTypeService>().SingleInstance();
            builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance();
            builder.RegisterType <SubscriptionService>().As <ISubscriptionService>().SingleInstance();
            builder.RegisterType <SettingService>().As <ISettingService>().InstancePerLifetimeScope();
            builder.RegisterType <PriceFormatter>().As <IPriceFormatter>().InstancePerLifetimeScope();
            builder.RegisterType <PriceCalculationService>().As <IPriceCalculationService>().InstancePerLifetimeScope();
            builder.RegisterType <ContractMonitorUpdateTask>().As <IScheduleTask>().InstancePerLifetimeScope();

            builder.RegisterType <ActionContextAccessor>().As <IActionContextAccessor>().InstancePerLifetimeScope();

            //register all settings
            builder.RegisterSource(new SettingsSource());

            //picture service
            if (!string.IsNullOrEmpty(config.AzureBlobStorageConnectionString))
            {
                builder.RegisterType <AzurePictureService>().As <IPictureService>().InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <PictureService>().As <IPictureService>().InstancePerLifetimeScope();
            }

            //installation service
            //if (!DataSettingsManager.DatabaseIsInstalled)
            //{
            //    if (config.UseFastInstallationService)
            //        builder.RegisterType<SqlFileInstallationService>().As<IInstallationService>().InstancePerLifetimeScope();
            //    //else
            //    //    builder.RegisterType<CodeFirstInstallationService>().As<IInstallationService>().InstancePerLifetimeScope();
            //}

            //event consumers
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer <>)).ToList();

            foreach (var consumer in consumers)
            {
                builder.RegisterType(consumer)
                .As(consumer.FindInterfaces((type, criteria) =>
                {
                    var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                    return(isMatch);
                }, typeof(IConsumer <>)))
                .InstancePerLifetimeScope();
            }
        }
Ejemplo n.º 12
0
 public RedisConnectionWrapper(GSConfig config)
 {
     this._config           = config;
     this._connectionString = new Lazy <string>(GetConnectionString);
     this._redisLockFactory = CreateRedisLockFactory();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, GSConfig config)
        {
            //installation localization service
            builder.RegisterType <InstallationLocalizationService>().As <IInstallationLocalizationService>().InstancePerLifetimeScope();

            //app work service
            builder.RegisterType <ConstructionTypeService>().As <IConstructionTypeService>().InstancePerLifetimeScope();
            builder.RegisterType <ReportService>().As <IReportService>().InstancePerLifetimeScope();
            builder.RegisterType <ConstructionCapitalService>().As <IConstructionCapitalService>().InstancePerLifetimeScope();
            builder.RegisterType <ConstructionService>().As <IConstructionService>().InstancePerLifetimeScope();
            builder.RegisterType <ContractAttributeService>().As <IContractAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <WidgetAppService>().As <IWidgetAppService>().InstancePerLifetimeScope();
            builder.RegisterType <TaskAttributeService>().As <ITaskAttributeService>().InstancePerLifetimeScope();
            builder.RegisterType <ContractFormService>().As <IContractFormService>().InstancePerLifetimeScope();
            builder.RegisterType <ContractTypeService>().As <IContractTypeService>().InstancePerLifetimeScope();
            builder.RegisterType <ContractPeriodService>().As <IContractPeriodService>().InstancePerLifetimeScope();
            builder.RegisterType <TaskGroupService>().As <ITaskGroupService>().InstancePerLifetimeScope();
            builder.RegisterType <UnitService>().As <IUnitService>().InstancePerLifetimeScope();
            builder.RegisterType <ProcuringAgencyService>().As <IProcuringAgencyService>().InstancePerLifetimeScope();
            builder.RegisterType <NotificationService>().As <INotificationService>().InstancePerLifetimeScope();
            builder.RegisterType <ContractService>().As <IContractService>().InstancePerLifetimeScope();
            builder.RegisterType <WorkFileService>().As <IWorkFileService>().InstancePerLifetimeScope();
            builder.RegisterType <WorkTaskService>().As <IWorkTaskService>().InstancePerLifetimeScope();
            builder.RegisterType <ContractLogService>().As <IContractLogService>().InstancePerLifetimeScope();
            builder.RegisterType <ContractPaymentService>().As <IContractPaymentService>().InstancePerLifetimeScope();
            builder.RegisterType <ContractRelateService>().As <IContractRelateService>().InstancePerLifetimeScope();
            builder.RegisterType <ContractMonitorService>().As <IContractMonitorService>().InstancePerLifetimeScope();
            builder.RegisterType <PaymentAdvanceService>().As <IPaymentAdvanceService>().InstancePerLifetimeScope();

            //common factories
            builder.RegisterType <AclSupportedModelFactory>().As <IAclSupportedModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <LocalizedModelFactory>().As <ILocalizedModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <StoreMappingSupportedModelFactory>().As <IStoreMappingSupportedModelFactory>().InstancePerLifetimeScope();

            //admin factories
            builder.RegisterType <BaseAdminModelFactory>().As <IBaseAdminModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ActivityLogModelFactory>().As <IActivityLogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <AddressAttributeModelFactory>().As <IAddressAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <BlogModelFactory>().As <IBlogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CategoryModelFactory>().As <ICategoryModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CommonModelFactory>().As <ICommonModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ContractAttributeModelFactory>().As <IContractAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <TaskAttributeModelFactory>().As <ITaskAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CountryModelFactory>().As <ICountryModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CurrencyModelFactory>().As <ICurrencyModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerAttributeModelFactory>().As <ICustomerAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerModelFactory>().As <ICustomerModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <CustomerRoleModelFactory>().As <ICustomerRoleModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <EmailAccountModelFactory>().As <IEmailAccountModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ExternalAuthenticationMethodModelFactory>().As <IExternalAuthenticationMethodModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ForumModelFactory>().As <IForumModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <HomeModelFactory>().As <IHomeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <LanguageModelFactory>().As <ILanguageModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <LogModelFactory>().As <ILogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ManufacturerModelFactory>().As <IManufacturerModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <MeasureModelFactory>().As <IMeasureModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <MessageTemplateModelFactory>().As <IMessageTemplateModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <NewsletterSubscriptionModelFactory>().As <INewsletterSubscriptionModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <NewsModelFactory>().As <INewsModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <PluginModelFactory>().As <IPluginModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <PollModelFactory>().As <IPollModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ReportModelFactory>().As <IReportModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <QueuedEmailModelFactory>().As <IQueuedEmailModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ReviewTypeModelFactory>().As <IReviewTypeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <ScheduleTaskModelFactory>().As <IScheduleTaskModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <SecurityModelFactory>().As <ISecurityModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <SettingModelFactory>().As <ISettingModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <SpecificationAttributeModelFactory>().As <ISpecificationAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <StoreModelFactory>().As <IStoreModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <TemplateModelFactory>().As <ITemplateModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <TopicModelFactory>().As <ITopicModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <VendorAttributeModelFactory>().As <IVendorAttributeModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <VendorModelFactory>().As <IVendorModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <WidgetModelFactory>().As <IWidgetModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <WidgetAppModelFactory>().As <IWidgetAppModelFactory>().InstancePerLifetimeScope();

            //factories
            builder.RegisterType <Factories.AddressModelFactory>().As <Factories.IAddressModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.BlogModelFactory>().As <Factories.IBlogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.CatalogModelFactory>().As <Factories.ICatalogModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.CommonModelFactory>().As <Factories.ICommonModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.CountryModelFactory>().As <Factories.ICountryModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.CustomerModelFactory>().As <Factories.ICustomerModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.ForumModelFactory>().As <Factories.IForumModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.ExternalAuthenticationModelFactory>().As <Factories.IExternalAuthenticationModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.NewsModelFactory>().As <Factories.INewsModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.NewsletterModelFactory>().As <Factories.INewsletterModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.PollModelFactory>().As <Factories.IPollModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.PrivateMessagesModelFactory>().As <Factories.IPrivateMessagesModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.ProfileModelFactory>().As <Factories.IProfileModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.TopicModelFactory>().As <Factories.ITopicModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.VendorModelFactory>().As <Factories.IVendorModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.WidgetModelFactory>().As <Factories.IWidgetModelFactory>().InstancePerLifetimeScope();

            //app work
            builder.RegisterType <Factories.ConstructionModelFactory>().As <Factories.IConstructionModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.TaskModelFactory>().As <Factories.ITaskModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.ContractModelFactory>().As <Factories.IContractModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.UnitModelFactory>().As <Factories.IUnitModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.ProcuringAgencyModelFactory>().As <Factories.IProcuringAgencyModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.WorkModelFactory>().As <Factories.IWorkModelFactory>().InstancePerLifetimeScope();
            builder.RegisterType <Factories.PaymentAdvanceFactory>().As <Factories.IPaymentAdvanceFactory>().InstancePerLifetimeScope();

            //
        }