/// <summary> /// Converts a <see cref="PersistenceReaderElement"/> to a <see cref="ResolvedParameter"/>, meaning persistence repository /// types referenced in configuration by name can be injected into the constructor of the parent provider. /// </summary> /// <remarks><see cref="ResolvedParameter"/> types allow for the deferred resolution of a type by using /// an <see cref="IComponentContext"/> to queue calls to resolve the instances, which would otherwise be /// tricky to do via chaining modules together</remarks> /// <returns>The parameter.</returns> public static ResolvedParameter ToParameter(this PersistenceReaderElement element) { PersistenceReaderElement localElement = element; return(new ResolvedParameter( (p, c) => (p.ParameterType == localElement.ToType() || p.Name == "reader" || localElement.ToType().IsAssignableFrom(p.ParameterType)), (p, c) => ResolveNamedPersistenceRepositoryProvider(c, localElement) )); }
//[TestMethod] public void TempGenerateConfigXmlFromTypes() { var instance = DependencyResolver.Current.Resolve <IFoundationConfigurationSection>(); var providers = instance.PersistenceProviders; var writeable = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None); instance = writeable.GetSection("rebel.foundation") as IFoundationConfigurationSection; providers = instance.PersistenceProviders; var provider1 = new PersistenceProviderElement(); provider1.Key = "in-memory-01"; provider1.Type = "Sandbox.PersistenceProviders.InMemoryMocked.Provider, Sandbox.PersistenceProviders.InMemoryMocked"; var reader1 = new PersistenceReaderElement(); reader1.Key = "reader"; reader1.Type = "Sandbox.PersistenceProviders.MockedInMemory.ReadWriteRepository, Sandbox.PersistenceProviders.MockedInMemory"; var writer1 = new PersistenceReadWriterElement(); writer1.Key = "writer"; writer1.Type = "Sandbox.PersistenceProviders.MockedInMemory.ReadWriteRepository, Sandbox.PersistenceProviders.MockedInMemory"; var writers = new PersistenceReadWriterElementCollection(); provider1.Reader = reader1; provider1.ReadWriters.Add(writer1); providers.Add(provider1); var filename = System.IO.Path.Combine(Path.GetDirectoryName(new System.Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), "test.config"); System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None). SaveAs(filename); var a = ((FoundationConfigurationSection)instance).GetXml(); Assert.Inconclusive(a); }
//[TestMethod] public void TempGenerateConfigXmlFromTypes() { var instance = DependencyResolver.Current.Resolve<IFoundationConfigurationSection>(); var providers = instance.PersistenceProviders; var writeable = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None); instance = writeable.GetSection("rebel.foundation") as IFoundationConfigurationSection; providers = instance.PersistenceProviders; var provider1 = new PersistenceProviderElement(); provider1.Key = "in-memory-01"; provider1.Type = "Sandbox.PersistenceProviders.InMemoryMocked.Provider, Sandbox.PersistenceProviders.InMemoryMocked"; var reader1 = new PersistenceReaderElement(); reader1.Key = "reader"; reader1.Type = "Sandbox.PersistenceProviders.MockedInMemory.ReadWriteRepository, Sandbox.PersistenceProviders.MockedInMemory"; var writer1 = new PersistenceReadWriterElement(); writer1.Key = "writer"; writer1.Type = "Sandbox.PersistenceProviders.MockedInMemory.ReadWriteRepository, Sandbox.PersistenceProviders.MockedInMemory"; var writers = new PersistenceReadWriterElementCollection(); provider1.Reader = reader1; provider1.ReadWriters.Add(writer1); providers.Add(provider1); var filename = System.IO.Path.Combine(Path.GetDirectoryName(new System.Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), "test.config"); System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None). SaveAs(filename); var a = ((FoundationConfigurationSection) instance).GetXml(); Assert.Inconclusive(a); }
/// <summary> /// Resolves the named persistence reader using an <see cref="IComponentContext"/>. /// </summary> /// <param name="context">The context.</param> /// <param name="providerElement">The provider element.</param> /// <returns></returns> /// <remarks></remarks> private static object ResolveNamedPersistenceRepositoryProvider(IComponentContext context, PersistenceReaderElement providerElement) { return(context.ResolveNamed(providerElement.InternalKey, providerElement.ToType())); }
/// <summary> /// Resolves the named persistence reader using an <see cref="IComponentContext"/>. /// </summary> /// <param name="context">The context.</param> /// <param name="providerElement">The provider element.</param> /// <returns></returns> /// <remarks></remarks> private static object ResolveNamedPersistenceRepositoryProvider(IComponentContext context, PersistenceReaderElement providerElement) { return context.ResolveNamed(providerElement.InternalKey, providerElement.ToType()); }