public void Configure(ConfigurationContext context, ContainerConfigurationBuilder builder, Type[] priorities) { var configurationSet = builder.RegistryBuilder.GetConfigurationSet(typeof(T)); Action action = delegate { var serviceConfigurationBuilder = new ServiceConfigurationBuilder <T>(configurationSet); var targetConfigurators = configurators .GroupBy(configurator => priorities == null ? 0 : GetLeafInterfaces(configurator).Max(x => Array.IndexOf(priorities, x.GetDefinition()))) .Where(x => x.Key >= 0) .OrderByDescending(x => x.Key) .DefaultIfEmpty(Enumerable.Empty <IServiceConfigurator <T> >()) .First(); foreach (var configurator in targetConfigurators) { try { configurator.Configure(context, serviceConfigurationBuilder); } catch (Exception e) { const string messageFormat = "error executing configurator [{0}]"; configurationSet.SetError(string.Format(messageFormat, configurator.GetType().FormatName()), e); return; } } }; configurationSet.RegisterLazyConfigurator(action); }
public void Configure(ConfigurationContext context, ContainerConfigurationBuilder builder, Type[] priorities) { foreach (var c in configurators) { c.Configure(context, builder); } }
public void Run(ContainerConfigurationBuilder builder, ConfigurationContext context, Type[] priorities) { foreach (var invoker in invokers) { invoker.Configure(context, builder, priorities); } }
public void Configure(ConfigurationContext context, ContainerConfigurationBuilder builder) { builder.Contract("all").UnionOf("c1", "c2", "c3"); builder.Contract("c1").BindDependency<FileAccessor>("fileName", "qq"); builder.Contract("c2").BindDependency<FileAccessor>("fileName", "ww1"); builder.Contract("c3").BindDependency<FileAccessor>("fileName", "ww2"); builder.WithInstanceFilter<FileAccessorWrap>(a => a.IsValid()); }
public ConfigurationRegistry Apply(TypesList typesList, Action<ContainerConfigurationBuilder> modificator) { if (modificator == null) return this; var builder = new ContainerConfigurationBuilder(); modificator(builder); return builder.RegistryBuilder.Build(typesList, this); }
public void Configure(ConfigurationContext context, ContainerConfigurationBuilder builder) { builder.Contract("all").UnionOf("c1", "c2", "c3"); builder.Contract("c1").BindDependency <FileAccessor>("fileName", "qq"); builder.Contract("c2").BindDependency <FileAccessor>("fileName", "ww1"); builder.Contract("c3").BindDependency <FileAccessor>("fileName", "ww2"); builder.WithInstanceFilter <FileAccessorWrap>(a => a.IsValid()); }
public void Configure(ConfigurationContext context, ContainerConfigurationBuilder builder) { builder.RegisterImplementationSelector( (interfaceType, implementationTypes, decisions) => decisions.Add(new ImplementationSelectorDecision { action = ImplementationSelectorDecision.Action.Exclude, target = typeof(DefaultA) })); }
public void Configure(ConfigurationContext context, ContainerConfigurationBuilder builder) { builder.ForAll("spec dependency for A1", (t, b) => { if (t == typeof(A1)) { b.Dependencies(new { parameter = 20 }); } }); }
public IContainer Build() { var typesContext = typesContextCache; if (typesContext == null) { var targetTypes = types() .Concat(Assembly.GetExecutingAssembly().GetTypes()) .Where(x => !x.Name.StartsWith("<>", StringComparison.OrdinalIgnoreCase)) .Distinct() .ToArray(); typesContext = new TypesContext { typesList = TypesList.Create(targetTypes) }; typesContext.genericsAutoCloser = new GenericsAutoCloser(typesContext.typesList, assembliesFilter); if (configFileName != null && File.Exists(configFileName)) { typesContext.fileConfigurator = FileConfigurationParser.Parse(typesContext.typesList.Types, configFileName); } ConfigurationRegistry staticConfiguration; if (staticConfigure == null) { staticConfiguration = ConfigurationRegistry.Empty; } else { var builder = new ContainerConfigurationBuilder(); staticConfigure(builder); staticConfiguration = builder.RegistryBuilder.Build(typesContext.typesList, null); } var configurationContainer = CreateContainer(typesContext, staticConfiguration); typesContext.configuratorRunner = configurationContainer.Get <ConfiguratorRunner>(); typesContextCache = typesContext; } ConfigurationRegistry configurationRegistry; if (!configurationByProfileCache.TryGetValue(profile ?? typeof(ContainerFactory), out configurationRegistry)) { var builder = new ContainerConfigurationBuilder(); var configurationContext = new ConfigurationContext(profile, settingsLoader, parameters); typesContext.configuratorRunner.Run(builder, configurationContext, priorities); if (typesContext.fileConfigurator != null) { typesContext.fileConfigurator(builder); } configurationRegistry = builder.RegistryBuilder.Build(typesContext.typesList, null); configurationByProfileCache.Add(profile ?? typeof(ContainerFactory), configurationRegistry); } return(CreateContainer(typesContext, configurationRegistry.Apply(typesContext.typesList, configure))); }
public void Configure(ConfigurationContext context, ContainerConfigurationBuilder builder) { builder.RegisterImplementationSelector( delegate(Type type, Type[] types, List <ImplementationSelectorDecision> decisions) { if (type == typeof(IA)) { decisions.Add(new ImplementationSelectorDecision { target = typeof(MyPrivateImpl), action = ImplementationSelectorDecision.Action.Include, comment = "private-impl" }); } }); }
public void Configure(ConfigurationContext context, ContainerConfigurationBuilder builder) { builder.BindDependency <SomeService>("value", context.Settings <MySettings>("my_context_key").value); }
public void Configure(ConfigurationContext context, ContainerConfigurationBuilder builder) { builder.Contract("composite-contract").UnionOf("c1", "c2"); }
public void Configure(ConfigurationContext context, ContainerConfigurationBuilder builder) { var selector = context.ProfileIs <InMemoryProfile>() ? GetSelector(true) : GetSelector(false); builder.RegisterImplementationSelector(selector); }
public void Configure(ConfigurationContext context, ContainerConfigurationBuilder builder) { builder.InheritorsOf <IRunnable>("runnables use parameters", (t, b) => b.Dependencies(context.Parameters)); }