private void Activating(IActivatingEventArgs <object> e) { var matchingAttachments = conventionManager.FindMatchingAttachments(e.Instance).Select(e.Context.Resolve); foreach (var attachment in matchingAttachments) { AttachmentHelper.Attach(attachment, e.Instance); } }
private static void SettingActivating(IActivatingEventArgs <object> args, IConfiguration configuration) { var section = args.Instance.GetType().GetCustomAttribute <ConfigSectionAttribute>(); if (section != null) { configuration.GetSection(section.SectionName).Bind(args.Instance); } SetKeyVaultSecrets(args.Instance, configuration); }
private void ActivateConfig(IActivatingEventArgs <LiteDbStoreConfiguration> e) { var hostingEnvironment = e.Context.Resolve <IHostingEnvironment>(); var dbDirectory = Path.Combine(hostingEnvironment.ContentRootPath, "database"); if (!Directory.Exists(dbDirectory)) { Directory.CreateDirectory(dbDirectory); } e.Instance.DbPath = Path.Combine(dbDirectory, "lite.db"); }
private static void AssignControllerInstance(IActivatingEventArgs<object> activatingArgs) { var controllerScenarioInstance = activatingArgs.Instance; var controllerProperty = controllerScenarioInstance .GetType() .GetProperties() .Single(x => x.PropertyType.IsConcreteTypeOf<BaseController>()); var controller = activatingArgs.Context.Resolve(controllerProperty.PropertyType); controllerProperty.SetValue(controllerScenarioInstance, controller); }
private static void ExchangeClientSecrets(IActivatingEventArgs <object> args, IConfiguration configuration) { if (args.Instance is Authentication.Identity identity) { foreach (var apiResourceDefinition in identity.ApiResourceDefinitions) { var optionalClientSecret = GetSettingsValue(apiResourceDefinition.ClientSecretName, configuration); if (optionalClientSecret.IsSome) { apiResourceDefinition.ClientSecret = optionalClientSecret.Value; } } } }
private static void SetupValues(IActivatingEventArgs <object> args, Microsoft.Extensions.Configuration.IConfiguration configuration) { var configInstance = args.Instance; var properties = configInstance.GetType().GetProperties(); foreach (var propertyInfo in properties) { var settingKey = propertyInfo.GetCustomAttributes <SettingsKeyAttribute>().SingleOrDefault(); if (settingKey != null) { SetValueIfSome(propertyInfo, configInstance, settingKey.AppSettingsKey, configuration); continue; } SetValueIfSome(propertyInfo, configInstance, propertyInfo.Name, configuration); } }
private void AssignFormValidatorFactoryWhenPostControllerScenario(IActivatingEventArgs<object> activatingArgs) { if (IsPostControllerScenario(activatingArgs.Instance)) { var postControllerScenarioInstance = activatingArgs.Instance; var formValidatorFactoryProperty = postControllerScenarioInstance .GetType() .GetProperties(BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance) .Single(p => p.PropertyType == typeof (IFormValidatorFactory)); formValidatorFactoryProperty .SetValue(postControllerScenarioInstance, activatingArgs.Context.Resolve<IFormValidatorFactory>()); } }
private void LoadConfiguration(IActivatingEventArgs <object> handler) { var settings = handler.Instance; var sectionName = GetSectionName(settings); if (sectionName != null) { // Lookup settings with the specified section name. var configuration = handler.Context.Resolve <IConfiguration>(); var section = configuration.GetSection(sectionName); // Bind the configuration to the settings instance. section.Bind(settings); } // Determine if the settings object can be validated. var validator = new ObjectValidator(settings); var validationResult = new ValidationResult(settings, validator); validationResult.ThrowIfInvalid(); }
private static void SetupValues(IActivatingEventArgs <object> args) { var configInstance = args.Instance; var properties = configInstance.GetType().GetProperties(); foreach (var propertyInfo in properties) { var settingKey = propertyInfo.GetCustomAttributes <SettingsKeyAttribute>().SingleOrDefault(); if (settingKey != null) { SetValueIfSome(propertyInfo, configInstance, settingKey.AppSettingsKey); continue; } if (SettingConnectionStringWhenAvailable(propertyInfo, configInstance)) { continue; } SetValueIfSome(propertyInfo, configInstance, propertyInfo.Name); } }
private static void ApplyInterception(Type[] interceptorTypes, IActivatingEventArgs <object> e, bool interceptAdditionalInterfaces) { Type type = e.Instance.GetType(); if (e.Component.Services.OfType <IServiceWithType>().Any(swt => !swt.ServiceType.GetTypeInfo().IsVisible) || type.Namespace == "Castle.Proxies") { return; } Type[] proxiedInterfaces = type.GetInterfaces().Where(i => i.GetTypeInfo().IsVisible).ToArray(); if (!proxiedInterfaces.Any()) { return; } Type theInterface = proxiedInterfaces.First(); Type[] interfaces = proxiedInterfaces.Skip(1).ToArray(); IList <IInterceptor> interceptorInstances = new List <IInterceptor>(); foreach (Type interceptorType in interceptorTypes) { interceptorInstances.Add((IInterceptor)e.Context.Resolve(interceptorType)); } if (interceptorInstances.Count > 0) { IInterceptor[] interceptors = interceptorInstances.ToArray(); object interceptedInstance = interceptAdditionalInterfaces ? generator.CreateInterfaceProxyWithTargetInterface(theInterface, interfaces, e.Instance, interceptors) : generator.CreateInterfaceProxyWithTargetInterface(theInterface, e.Instance, interceptors); e.ReplaceInstance(interceptedInstance); } }
private void RunMigrations(IActivatingEventArgs<ISessionFactory> activatingEventArgs) { var migrator = activatingEventArgs.Context.Resolve<ISchemaMigrator>(); migrator.Migrate(); }
static void OnComponentActivating(object sender, IActivatingEventArgs<IMcManageConfig> e) { e.Instance.Load(Properties.Resources.configpath,Properties.Resources.defaultconfig); }
private void Handler(IActivatingEventArgs <IRegistryAccess> obj) { obj.ReplaceInstance(new RegistryAccess(Application.CompanyName, Application.ProductName)); }
private void RunMigrations(IActivatingEventArgs <ISessionFactory> activatingEventArgs) { var migrator = activatingEventArgs.Context.Resolve <ISchemaMigrator>(); migrator.Migrate(); }
private static void ConfigureUserIdentityProvider(IActivatingEventArgs<object> e) { var viewModel = (IHaveCustomMappings) e.Instance; viewModel.UserIdentityProvider = e.Context.Resolve<Func<IPrincipal>>(); }
private static void InitializeProperty(IActivatingEventArgs <BaseStory> e) { e.Instance.Cfg = e.Context.Resolve <Config>(); e.Instance.Log = e.Context.Resolve <ILogger>(); e.Instance.Util = e.Context.Resolve <Util>(); }
private static void ActivateInject <T>(IActivatingEventArgs <T> args) { PropertyInjector.InjectProperties(args.Context, args.Instance); }