public ContainerFactory WithInfoLogger(LogInfo logger) { infoLogger = logger; typesContextCache = null; configurationByProfileCache.Clear(); return(this); }
public ContainerFactory WithConfigFile(string fileName) { configFileName = fileName; typesContextCache = null; configurationByProfileCache.Clear(); return(this); }
public ContainerFactory WithErrorLogger(LogError logger) { errorLogger = logger; typesContextCache = null; configurationByProfileCache.Clear(); return(this); }
public ContainerFactory WithValueFormatter <T>(Func <T, string> formatter) { valueFormatters[typeof(T)] = o => formatter((T)o); typesContextCache = null; configurationByProfileCache.Clear(); return(this); }
public ContainerFactory WithAssembliesFilter(Func <AssemblyName, bool> newAssembliesFilter) { assembliesFilter = n => newAssembliesFilter(n) || n.Name == "SimpleContainer"; typesContextCache = null; configurationByProfileCache.Clear(); return(this); }
public ContainerFactory WithTypes(Type[] newTypes) { types = () => newTypes; typesContextCache = null; configurationByProfileCache.Clear(); return(this); }
public ContainerFactory WithStaticConfigurator(Action <ContainerConfigurationBuilder> newConfigure) { staticConfigure = newConfigure; typesContextCache = null; configurationByProfileCache.Clear(); return(this); }
private IContainer CreateContainer(TypesContext currentTypesContext, ConfigurationRegistry configuration) { return(new Implementation.SimpleContainer(configuration, new ContainerContext { infoLogger = infoLogger, genericsAutoCloser = currentTypesContext.genericsAutoCloser, typesList = currentTypesContext.typesList, valueFormatters = valueFormatters }, errorLogger)); }
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))); }
private ContainerFactory WithTypesFromAssemblies(ParallelQuery <Assembly> assemblies) { var newTypes = assemblies .Where(x => assembliesFilter(x.GetName())) .SelectMany(a => { try { return(a.GetTypes()); } catch (ReflectionTypeLoadException e) { const string messageFormat = "can't load types from assembly [{0}], loaderExceptions:\r\n{1}"; var loaderExceptionsText = e.LoaderExceptions.Select(ex => ex.ToString()).JoinStrings("\r\n"); throw new SimpleContainerException(string.Format(messageFormat, a.GetName(), loaderExceptionsText), e); } }); types = newTypes.ToArray; typesContextCache = null; return(this); }