public WorkflowMessageService( IMessageTemplateService messageTemplateService, IMessageTokenProvider messageTokenProvider, IQueuedEmailService queuedEmailService, ITokenizer tokenizer, AldanConfig config) { _messageTemplateService = messageTemplateService; _messageTokenProvider = messageTokenProvider; _queuedEmailService = queuedEmailService; _tokenizer = tokenizer; _config = config; }
public MessageTokenProvider( IActionContextAccessor actionContextAccessor, IUserService userService, IUrlHelperFactory urlHelperFactory, AldanConfig config, IGenericAttributeService genericAttributeService) { _actionContextAccessor = actionContextAccessor; _userService = userService; _urlHelperFactory = urlHelperFactory; _config = config; _genericAttributeService = genericAttributeService; }
public AldanObjectContext CreateDbContext(string[] args) { IConfiguration configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory() + "/../../Presentation/Aldan.Web/") .AddJsonFile("appsettings.json", false, false) .Build(); var config = new AldanConfig(); configuration.GetSection("Aldan").Bind(config); string connectionString = config.Data.ConnectionString; var builder = new DbContextOptionsBuilder <AldanObjectContext>() .UseSqlServer(connectionString); return(new AldanObjectContext(builder.Options)); }
public UserController( IUserModelFactory userModelFactory, IWorkContext workContext, IUserService userService, IUserRegistrationService userRegistrationService, INotificationService notificationService, IQueuedEmailService queuedEmailService, AldanConfig config, IWorkflowMessageService workflowMessageService, IGenericAttributeService genericAttributeService) { _userModelFactory = userModelFactory; _workContext = workContext; _userService = userService; _userRegistrationService = userRegistrationService; _notificationService = notificationService; _queuedEmailService = queuedEmailService; _config = config; _workflowMessageService = workflowMessageService; _genericAttributeService = genericAttributeService; }
public EncryptionService(AldanConfig aldanConfig) { _aldanConfig = aldanConfig; }
/// <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, AldanConfig config) { //file provider builder.RegisterType <AldanFileProvider>().As <IAldanFileProvider>().InstancePerLifetimeScope(); //web helper builder.RegisterType <WebHelper>().As <IWebHelper>().InstancePerLifetimeScope(); builder.Register(context => new AldanObjectContext(context.Resolve <DbContextOptions <AldanObjectContext> >())) .As <IDbContext>().InstancePerLifetimeScope(); //repositories builder.RegisterGeneric(typeof(EfRepository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope(); //cache manager builder.RegisterType <PerRequestCacheManager>().As <ICacheManager>().InstancePerLifetimeScope(); builder.RegisterType <MemoryCacheManager>() .As <ILocker>() .As <IStaticCacheManager>() .SingleInstance(); //work context builder.RegisterType <WebWorkContext>().As <IWorkContext>().InstancePerLifetimeScope(); //services builder.RegisterType <DefaultLogger>().As <ILogger>().InstancePerLifetimeScope(); builder.RegisterType <ScheduleTaskService>().As <IScheduleTaskService>().InstancePerLifetimeScope(); builder.RegisterType <ActionContextAccessor>().As <IActionContextAccessor>().InstancePerLifetimeScope(); builder.RegisterType <EncryptionService>().As <IEncryptionService>().InstancePerLifetimeScope(); builder.RegisterType <CookieAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope(); builder.RegisterType <UserService>().As <IUserService>().InstancePerLifetimeScope(); builder.RegisterType <UserRegistrationService>().As <IUserRegistrationService>().InstancePerLifetimeScope(); builder.RegisterType <GenericAttributeService>().As <IGenericAttributeService>().InstancePerLifetimeScope(); builder.RegisterType <MessageTemplateService>().As <IMessageTemplateService>().InstancePerLifetimeScope(); builder.RegisterType <QueuedEmailService>().As <IQueuedEmailService>().InstancePerLifetimeScope(); builder.RegisterType <NotificationService>().As <INotificationService>().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 <RoutePublisher>().As <IRoutePublisher>().SingleInstance(); builder.RegisterType <EventPublisher>().As <IEventPublisher>().SingleInstance(); //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(); } }
/// <summary> /// Register dependencies /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="typeFinder">Type finder</param> /// <param name="aldanConfig">Aldan configuration parameters</param> protected virtual IServiceProvider RegisterDependencies(IServiceCollection services, ITypeFinder typeFinder, AldanConfig aldanConfig) { var containerBuilder = new ContainerBuilder(); //register engine containerBuilder.RegisterInstance(this).As <IEngine>().SingleInstance(); //register type finder containerBuilder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance(); //populate Autofac container builder with the set of registered service descriptors containerBuilder.Populate(services); //find dependency registrars provided by other assemblies var dependencyRegistrars = typeFinder.FindClassesOfType <IDependencyRegistrar>(); //create and sort instances of dependency registrars var instances = dependencyRegistrars .Select(dependencyRegistrar => (IDependencyRegistrar)Activator.CreateInstance(dependencyRegistrar)) .OrderBy(dependencyRegistrar => dependencyRegistrar.Order); //register all provided dependencies foreach (var dependencyRegistrar in instances) { dependencyRegistrar.Register(containerBuilder, typeFinder, aldanConfig); } //create service provider _serviceProvider = new AutofacServiceProvider(containerBuilder.Build()); return(_serviceProvider); }
/// <summary> /// Add and configure services /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration of the application</param> /// <param name="aldanConfig">Aldan configuration parameters</param> /// <returns>Service provider</returns> public IServiceProvider ConfigureServices(IServiceCollection services, IConfiguration configuration, AldanConfig aldanConfig) { //find startup configurations provided by other assemblies var typeFinder = new WebAppTypeFinder(); var startupConfigurations = typeFinder.FindClassesOfType <IAldanStartup>(); //create and sort instances of startup configurations var instances = startupConfigurations .Select(startup => (IAldanStartup)Activator.CreateInstance(startup)) .OrderBy(startup => startup.Order); //configure services foreach (var instance in instances) { instance.ConfigureServices(services, configuration); } //register mapper configurations AddAutoMapper(services, typeFinder); //register dependencies RegisterDependencies(services, typeFinder, aldanConfig); //run startup tasks RunStartupTasks(typeFinder); //resolve assemblies here. otherwise, plugins can throw an exception when rendering views AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; return(_serviceProvider); }
/// <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, AldanConfig config) { builder.RegisterType <Aldan.Web.Factories.UserModelFactory>().As <Aldan.Web.Factories.IUserModelFactory>().InstancePerLifetimeScope(); builder.RegisterType <Aldan.Web.Areas.Admin.Factories.CommonModelFactory>().As <Aldan.Web.Areas.Admin.Factories.ICommonModelFactory>().InstancePerLifetimeScope(); builder.RegisterType <Aldan.Web.Areas.Admin.Factories.UserModelFactory>().As <Aldan.Web.Areas.Admin.Factories.IUserModelFactory>().InstancePerLifetimeScope(); builder.RegisterType <QueuedEmailModelFactory>().As <IQueuedEmailModelFactory>().InstancePerLifetimeScope(); builder.RegisterType <MessageTemplateModelFactory>().As <IMessageTemplateModelFactory>() .InstancePerLifetimeScope(); builder.RegisterType <Aldan.Web.Factories.CommonModelFactory>().As <Aldan.Web.Factories.ICommonModelFactory>().InstancePerLifetimeScope(); builder.RegisterType <LogModelFactory>().As <ILogModelFactory>().InstancePerLifetimeScope(); builder.RegisterType <ScheduleTaskModelFactory>().As <IScheduleTaskModelFactory>().InstancePerLifetimeScope(); builder.RegisterType <BaseAdminModelFactory>().As <IBaseAdminModelFactory>().InstancePerLifetimeScope(); }
public EmailSender(AldanConfig config) { _config = config; }