public void Install(IObjectFactoryBuilder builder) { var objectFactory = builder.BuildObjectFactory(); var paperCatalog = new AggregateCatalog(); var exposedCatalog = objectFactory.CreateObject <ExposedPaperCatalog>(); paperCatalog.AddCatalog(exposedCatalog); foreach (var type in ExposedTypes.GetTypes <IPaperCatalog>()) { try { var catalog = (IPaperCatalog)objectFactory.CreateObject(type); paperCatalog.AddCatalog(catalog); } catch (Exception ex) { ex.Trace(); } } builder.AddSingleton <IPaperCatalog>(paperCatalog); }
public void Register(IObjectFactoryBuilder builder) { lock (sync) { FactoryBuilders.Add(builder); ShouldUpdateScope = true; } }
public static void Configure(IObjectFactoryBuilder builder, Database db) { //TODO: register applications as implementation only builder.RegisterType <RestApplication>(); builder.RegisterType <RestApplication, IRestApplication>(); builder.RegisterType <SoapApplication>(); builder.RegisterType <SoapApplication, ISoapApplication>(); builder.RegisterType <CommandConverter, ICommandConverter>(); var cs = ConfigurationManager.AppSettings["Revenj.ConnectionString"] ?? ConfigurationManager.AppSettings["ConnectionString"]; if (db == Database.Postgres) { if (string.IsNullOrEmpty(cs)) { throw new ConfigurationErrorsException(@"ConnectionString is missing from configuration. Add ConnectionString to <appSettings> Example: <add key=""ConnectionString"" value=""server=postgres.localhost;port=5432;database=MyDatabase;user=postgres;password=123456;encoding=unicode"" />"); } SetupPostgres(builder, cs); } else if (db == Database.Oracle) { if (string.IsNullOrEmpty(cs)) { throw new ConfigurationErrorsException(@"ConnectionString is missing from configuration. Add ConnectionString to <appSettings> Example: <add key=""ConnectionString"" value=""Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyOracleHost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=xe)));User Id=oracle;Password=123456;"" />"); } SetupOracle(builder, cs); } var serverModels = (from key in ConfigurationManager.AppSettings.AllKeys where key.StartsWith("ServerAssembly", StringComparison.OrdinalIgnoreCase) select LoadAssembly(ConfigurationManager.AppSettings[key])) .ToList(); if (serverModels.Count == 0) { serverModels = (from asm in Revenj.Utility.AssemblyScanner.GetAssemblies() let type = asm.GetType("SystemBoot.Configuration") where type != null && type.GetMethod("Initialize") != null select asm) .ToList(); if (serverModels.Count == 0) { throw new ConfigurationErrorsException(@"Server assemblies not found. When running in compiled mode, server assemblies must be deployed with other assemblies. Alternatively, explicitly specify sever assembly in the configuration file. Example: <add key=""ServerAssembly_Domain"" value=""AppDomainModel.dll"" />"); } } builder.ConfigurePatterns(_ => serverModels); builder.ConfigureSerialization(); builder.ConfigureSecurity(true); builder.ConfigureProcessing(); }
/// <summary> /// Register instance to the container builder. /// Registered instance will be available in nested scopes too. /// </summary> /// <typeparam name="T">service</typeparam> /// <param name="builder">container builder</param> /// <param name="instance">provided instance</param> public static void RegisterSingleton <T>(this IObjectFactoryBuilder builder, T instance) { Contract.Requires(builder != null); Contract.Requires(instance != null); builder.Add(new FactoryBuilderInstance { instance = instance, AsType = typeof(T) }); }
/// <summary> /// Register factory to the container builder with specified scope. Default scope is Transient. /// Service will be resolved from the factory using context scope. /// </summary> /// <typeparam name="T">service type</typeparam> /// <param name="builder">container builder</param> /// <param name="func">factory to service</param> /// <param name="scope">factory scope</param> public static void RegisterFunc <T>(this IObjectFactoryBuilder builder, Func <IObjectFactory, T> func, InstanceScope scope = InstanceScope.Transient) { Contract.Requires(builder != null); Contract.Requires(func != null); builder.Add(new FactoryBuilderFunc { func = f => func(f), AsType = new[] { typeof(T) }, Scope = scope }); }
internal static void SetupPostgres(IObjectFactoryBuilder builder) { var cs = ConfigurationManager.AppSettings["Revenj.ConnectionString"] ?? ConfigurationManager.AppSettings["ConnectionString"]; if (string.IsNullOrEmpty(cs)) throw new ConfigurationErrorsException(@"ConnectionString is missing from configuration. Add ConnectionString to <appSettings> Example: <add key=""ConnectionString"" value=""server=postgres.localhost;port=5432;database=MyDatabase;user=postgres;password=123456;encoding=unicode"" />"); Revenj.DatabasePersistence.Postgres.Setup.ConfigurePostgres(builder, cs); }
/// <summary> /// Register specified type to the container. Default scope is transient /// </summary> /// <typeparam name="TService">service type</typeparam> /// <param name="builder">container builder</param> /// <param name="scope">resolution scope</param> public static void RegisterType <TService>( this IObjectFactoryBuilder builder, InstanceScope scope = InstanceScope.Transient) { Contract.Requires(builder != null); builder.Add(new FactoryBuilderType { type = typeof(TService), Scope = scope, IsGeneric = false }); }
public static void ConfigureOracle(this IObjectFactoryBuilder builder, string connectionString) { builder.RegisterSingleton(new Revenj.DatabasePersistence.Oracle.ConnectionInfo(connectionString)); builder.RegisterType <OracleQueryManager, IDatabaseQueryManager>(InstanceScope.Context); builder.RegisterType <OracleDatabaseQuery, IOracleDatabaseQuery>(); builder.RegisterFunc(c => c.Resolve <IDatabaseQueryManager>().CreateQuery(), InstanceScope.Context); builder.RegisterType <OracleAdvancedQueueNotification, IDataChangeNotification, IEagerNotification>(InstanceScope.Singleton); builder.RegisterType <OracleObjectFactory, IOracleConverterRepository, IOracleConverterFactory>(InstanceScope.Singleton); builder.RegisterType <QueryExecutor>(); }
/// <summary> /// Register specified type to the container as custom services. Default scope is transient /// </summary> /// <typeparam name="TService">service implementation</typeparam> /// <typeparam name="TAs1">service type</typeparam> /// <typeparam name="TAs2">additional service type</typeparam> /// <param name="builder">container builder</param> /// <param name="scope">resolution scope</param> public static void RegisterType <TService, TAs1, TAs2>( this IObjectFactoryBuilder builder, InstanceScope scope = InstanceScope.Transient) where TService : TAs1, TAs2 { Contract.Requires(builder != null); builder.Add(new FactoryBuilderType { type = typeof(TService), Scope = scope, AsType = new[] { typeof(TAs1), typeof(TAs2) }, IsGeneric = false }); }
public static void ConfigureSerialization(this IObjectFactoryBuilder builder) { builder.RegisterType <GenericDataContractResolver>(InstanceScope.Singleton); builder.RegisterType(typeof(XmlSerialization), InstanceScope.Singleton, false, typeof(ISerialization <XElement>)); builder.RegisterType <GenericDeserializationBinder, GenericDeserializationBinder, SerializationBinder>(InstanceScope.Singleton); builder.RegisterType(typeof(BinarySerialization), InstanceScope.Singleton, false, typeof(ISerialization <byte[]>)); builder.RegisterType(typeof(JsonSerialization), InstanceScope.Singleton, false, typeof(ISerialization <string>), typeof(ISerialization <TextReader>)); builder.RegisterType(typeof(ProtobufSerialization), InstanceScope.Singleton, false, typeof(ISerialization <MemoryStream>), typeof(ISerialization <Stream>)); builder.RegisterType(typeof(PassThroughSerialization), InstanceScope.Singleton, false, typeof(ISerialization <object>)); builder.RegisterType <WireSerialization, IWireSerialization>(InstanceScope.Singleton); }
internal static void SetupPostgres(IObjectFactoryBuilder builder) { var cs = ConfigurationManager.AppSettings["Revenj.ConnectionString"] ?? ConfigurationManager.AppSettings["ConnectionString"]; if (string.IsNullOrEmpty(cs)) { throw new ConfigurationErrorsException(@"ConnectionString is missing from configuration. Add ConnectionString to <appSettings> Example: <add key=""ConnectionString"" value=""server=postgres.localhost;port=5432;database=MyDatabase;user=postgres;password=123456;encoding=unicode"" />"); } Revenj.DatabasePersistence.Postgres.Setup.ConfigurePostgres(builder, cs); }
public static void ConfigurePatterns(this IObjectFactoryBuilder builder, Func <IObjectFactory, IEnumerable <Assembly> > getDomainModels) { builder.RegisterFunc <IDomainModel>(c => new DomainModel(getDomainModels(c), c), InstanceScope.Singleton); builder.RegisterType <DomainTypeResolver, ITypeResolver>(InstanceScope.Singleton); builder.RegisterType(typeof(WeakCache <>), InstanceScope.Context, true, typeof(WeakCache <>), typeof(IDataCache <>)); builder.RegisterType <DomainEventSource, IDomainEventSource>(InstanceScope.Context); builder.RegisterType <DomainEventStore, IDomainEventStore>(InstanceScope.Context); builder.RegisterType <GlobalEventStore>(InstanceScope.Context); builder.RegisterType(typeof(SingleDomainEventSource <>), InstanceScope.Context, true, typeof(IDomainEventSource <>)); builder.RegisterType(typeof(RegisterChangeNotifications <>), InstanceScope.Singleton, true, typeof(IObservable <>)); builder.RegisterType <DataContext, IDataContext>(InstanceScope.Context); }
public static void ConfigureSecurity(this IObjectFactoryBuilder builder, bool withAuth) { if (withAuth) { builder.RegisterType(typeof(RepositoryAuthentication), InstanceScope.Singleton, false, typeof(IAuthentication <SecureString>), typeof(IAuthentication <string>), typeof(IAuthentication <byte[]>)); builder.RegisterType <RepositoryPrincipalFactory, IPrincipalFactory>(); } builder.RegisterType <PermissionManager, IPermissionManager>(InstanceScope.Singleton); builder.RegisterFunc <IPrincipal>(_ => System.Threading.Thread.CurrentPrincipal, InstanceScope.Context); }
public static void Configure(IObjectFactoryBuilder builder, Database db) { //TODO: register applications as implementation only builder.RegisterType<RestApplication>(); builder.RegisterType<RestApplication, IRestApplication>(); builder.RegisterType<SoapApplication>(); builder.RegisterType<SoapApplication, ISoapApplication>(); builder.RegisterType<CommandConverter, ICommandConverter>(); var cs = ConfigurationManager.AppSettings["Revenj.ConnectionString"] ?? ConfigurationManager.AppSettings["ConnectionString"]; if (db == Database.Postgres) { if (string.IsNullOrEmpty(cs)) throw new ConfigurationErrorsException(@"ConnectionString is missing from configuration. Add ConnectionString to <appSettings> Example: <add key=""ConnectionString"" value=""server=postgres.localhost;port=5432;database=MyDatabase;user=postgres;password=123456;encoding=unicode"" />"); SetupPostgres(builder, cs); } else if (db == Database.Oracle) { if (string.IsNullOrEmpty(cs)) throw new ConfigurationErrorsException(@"ConnectionString is missing from configuration. Add ConnectionString to <appSettings> Example: <add key=""ConnectionString"" value=""Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyOracleHost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=xe)));User Id=oracle;Password=123456;"" />"); SetupOracle(builder, cs); } var serverModels = (from key in ConfigurationManager.AppSettings.AllKeys where key.StartsWith("ServerAssembly", StringComparison.OrdinalIgnoreCase) select LoadAssembly(ConfigurationManager.AppSettings[key])) .ToList(); if (serverModels.Count == 0) { serverModels = (from asm in Revenj.Utility.AssemblyScanner.GetAssemblies() let type = asm.GetType("SystemBoot.Configuration") where type != null && type.GetMethod("Initialize") != null select asm) .ToList(); if (serverModels.Count == 0) throw new ConfigurationErrorsException(@"Server assemblies not found. When running in compiled mode, server assemblies must be deployed with other assemblies. Alternatively, explicitly specify sever assembly in the configuration file. Example: <add key=""ServerAssembly_Domain"" value=""AppDomainModel.dll"" />"); } builder.ConfigurePatterns(_ => serverModels); builder.ConfigureSerialization(); builder.ConfigureSecurity(true); builder.ConfigureProcessing(); }
/// <summary> /// Register specified type to the container as custom service with provided scope. /// </summary> /// <param name="builder">container builder</param> /// <param name="type">service type</param> /// <param name="asType">register as</param> /// <param name="scope">resolution scope</param> /// <param name="isGeneric">is generic type</param> public static void RegisterType( this IObjectFactoryBuilder builder, Type type, InstanceScope scope, bool isGeneric, params Type[] asType) { Contract.Requires(builder != null); Contract.Requires(type != null); builder.Add(new FactoryBuilderType { type = type, Scope = scope, AsType = asType, IsGeneric = isGeneric }); }
public static void ConfigurePostgres(this IObjectFactoryBuilder builder, string connectionString) { var ci = new Revenj.DatabasePersistence.Postgres.ConnectionInfo(connectionString); builder.RegisterSingleton(ci); builder.RegisterType <PostgresConnectionPool, IConnectionPool>(InstanceScope.Singleton); builder.RegisterType <PostgresQueryManager, IDatabaseQueryManager>(InstanceScope.Context); builder.RegisterType <PostgresDatabaseQuery, IPostgresDatabaseQuery>(); builder.RegisterFunc(c => c.Resolve <IDatabaseQueryManager>().CreateQuery(), InstanceScope.Context); builder.RegisterType <PostgresDatabaseNotification, IDataChangeNotification, IEagerNotification>(InstanceScope.Singleton); builder.RegisterType <PostgresObjectFactory, IPostgresConverterRepository, IPostgresConverterFactory>(InstanceScope.Singleton); builder.RegisterType <QueryExecutor>(); builder.RegisterSingleton <IPostgresVersionInfo>(new PostgresVersionInfo(ci)); builder.RegisterFunc(c => BulkReaderHelper.BulkRead(c, ChunkedMemoryStream.Create()), InstanceScope.Context); }
public void ConfigureServices(IObjectFactoryBuilder builder) { var paperCatalog = new PaperCatalog(); paperCatalog.Fill(); Console.WriteLine("--papers--"); foreach (var key in paperCatalog.Keys) { Console.WriteLine($"{key} => /Paper/Api/1/Modules/{key.Module}/Papers/{key.Schema}"); } Console.WriteLine("----"); builder.AddSingleton <IPaperCatalog>(paperCatalog); }
public static void Configure(IObjectFactoryBuilder builder, Action <IObjectFactoryBuilder> db) { //TODO: register applications as implementation only builder.RegisterType <RestApplication>(); builder.RegisterType <RestApplication, IRestApplication>(); builder.RegisterType <SoapApplication>(); builder.RegisterType <SoapApplication, ISoapApplication>(); builder.RegisterType <CommandConverter, ICommandConverter>(); if (db != null) { db(builder); } var serverModels = (from key in ConfigurationManager.AppSettings.AllKeys where key.StartsWith("ServerAssembly", StringComparison.OrdinalIgnoreCase) select LoadAssembly(ConfigurationManager.AppSettings[key])) .ToList(); if (serverModels.Count == 0) { serverModels = (from asm in Revenj.Utility.AssemblyScanner.GetAssemblies() let type = asm.GetType("SystemBoot.Configuration") where type != null && type.GetMethod("Initialize") != null select asm) .ToList(); if (serverModels.Count == 0) { if (ConfigurationManager.AppSettings["ServerModel"] != "None") { throw new ConfigurationErrorsException(@"Server assemblies not found. When running in compiled mode, server assemblies must be deployed with other assemblies. Alternatively, explicitly specify sever assembly in the configuration file. Example: <add key=""ServerAssembly_Domain"" value=""AppDomainModel.dll"" /> If you wish to run Revenj without server assemblies specify ServerModel = None as: <add key=""ServerModel"" value=""None"" />"); } } } builder.ConfigurePatterns(_ => serverModels); builder.ConfigureSerialization(); builder.ConfigureSecurity(true); builder.ConfigureProcessing(); }
public static IObjectFactoryBuilder AddPaperObjects(this IObjectFactoryBuilder builder) { var factory = builder.ObjectFactory; var pipelineCatalog = new PipelineCatalog(); var siteMapCatalog = new SiteMapCatalog(); var paperCatalog = new PaperCatalog(); builder.AddSingleton <IObjectFactory>(factory); builder.AddSingleton <IPipelineCatalog>(pipelineCatalog); builder.AddSingleton <ISiteMapCatalog>(siteMapCatalog); builder.AddSingleton <IPaperCatalog>(paperCatalog); pipelineCatalog.ImportExposedCollections(factory); siteMapCatalog.ImportExposedCollections(factory); paperCatalog.ImportExposedCollections(factory); return(builder); }
public static void Configure(IObjectFactoryBuilder builder, Action<IObjectFactoryBuilder> db) { //TODO: register applications as implementation only builder.RegisterType<RestApplication>(); builder.RegisterType<RestApplication, IRestApplication>(); builder.RegisterType<SoapApplication>(); builder.RegisterType<SoapApplication, ISoapApplication>(); builder.RegisterType<CommandConverter, ICommandConverter>(); if (db != null) db(builder); var serverModels = (from key in ConfigurationManager.AppSettings.AllKeys where key.StartsWith("ServerAssembly", StringComparison.OrdinalIgnoreCase) select LoadAssembly(ConfigurationManager.AppSettings[key])) .ToList(); if (serverModels.Count == 0) { serverModels = (from asm in Revenj.Utility.AssemblyScanner.GetAssemblies() let type = asm.GetType("SystemBoot.Configuration") where type != null && type.GetMethod("Initialize") != null select asm) .ToList(); if (serverModels.Count == 0) { if (ConfigurationManager.AppSettings["ServerModel"] != "None") { throw new ConfigurationErrorsException(@"Server assemblies not found. When running in compiled mode, server assemblies must be deployed with other assemblies. Alternatively, explicitly specify sever assembly in the configuration file. Example: <add key=""ServerAssembly_Domain"" value=""AppDomainModel.dll"" /> If you wish to run Revenj without server assemblies specify ServerModel = None as: <add key=""ServerModel"" value=""None"" />"); } } } builder.ConfigurePatterns(_ => serverModels); builder.ConfigureSerialization(); builder.ConfigureSecurity(true); builder.ConfigureProcessing(); }
internal static void RegisterToContainer(ContainerBuilder cb, IObjectFactoryBuilder rb, ConcurrentDictionary <Type, bool> cache) { foreach (var item in rb.Types.Where(i => i.IsGeneric == false)) { if (cache != null) { if (item.AsType != null) { foreach (var t in item.AsType) { cache.TryAdd(t, true); } } else { cache.TryAdd(item.Type, true); } } switch (item.Scope) { case InstanceScope.Transient: if (item.AsType == null || item.AsType.Length == 0) { cb.RegisterType(item.Type); } else { cb.RegisterType(item.Type).As(item.AsType); } break; case InstanceScope.Singleton: if (item.AsType == null || item.AsType.Length == 0) { cb.RegisterType(item.Type).SingleInstance(); } else { cb.RegisterType(item.Type).As(item.AsType).SingleInstance(); } break; default: if (item.AsType == null || item.AsType.Length == 0) { cb.RegisterType(item.Type).InstancePerLifetimeScope(); } else { cb.RegisterType(item.Type).As(item.AsType).InstancePerLifetimeScope(); } break; } } foreach (var item in rb.Types.Where(i => i.IsGeneric)) { if (cache != null) { if (item.AsType != null) { foreach (var t in item.AsType) { cache.TryAdd(t, true); } } else { cache.TryAdd(item.Type, true); } } switch (item.Scope) { case InstanceScope.Transient: if (item.AsType == null || item.AsType.Length == 0) { cb.RegisterGeneric(item.Type); } else { cb.RegisterGeneric(item.Type).As(item.AsType); } break; case InstanceScope.Singleton: if (item.AsType == null || item.AsType.Length == 0) { cb.RegisterGeneric(item.Type).SingleInstance(); } else { cb.RegisterGeneric(item.Type).As(item.AsType).SingleInstance(); } break; default: if (item.AsType == null || item.AsType.Length == 0) { cb.RegisterGeneric(item.Type).InstancePerLifetimeScope(); } else { cb.RegisterGeneric(item.Type).As(item.AsType).InstancePerLifetimeScope(); } break; } } foreach (var item in rb.Instances) { var type = item.AsType ?? item.Instance.GetType(); if (cache != null) { cache.TryAdd(type, true); } cb.RegisterInstance(item.Instance).As(type); } foreach (var it in rb.Funcs) { var item = it; if (item.AsType == null || item.AsType.Length == 0) { throw new NotSupportedException("Result type must be defined. Declared Func result is not defined"); } if (cache != null) { foreach (var t in item.AsType) { cache.TryAdd(t, true); } } switch (item.Scope) { case InstanceScope.Transient: cb.Register(c => item.Func(c.Resolve <IObjectFactory>())).As(item.AsType); break; case InstanceScope.Singleton: cb.Register(c => item.Func(c.Resolve <IObjectFactory>())).As(item.AsType).SingleInstance(); break; default: cb.Register(c => item.Func(c.Resolve <IObjectFactory>())).As(item.AsType).InstancePerLifetimeScope(); break; } } }
private static void SetupPostgres(IObjectFactoryBuilder builder, string connectionString) { Revenj.DatabasePersistence.Postgres.Setup.ConfigurePostgres(builder, connectionString); }
public void Register(IObjectFactoryBuilder builder) { Container.Register(builder); }
public void Register(IObjectFactoryBuilder builder) { lock (sync) { FactoryBuilders.Add(builder); ShouldBuildScope = true; } }
internal static void RegisterToContainer(IContainer cb, IObjectFactoryBuilder rb) { foreach (var item in rb.Types) { switch (item.Scope) { case InstanceScope.Transient: if (item.AsType == null || item.AsType.Length == 0) { cb.Register(item.Type, Reuse.Transient); } else { foreach (var t in item.AsType) { cb.Register(t, item.Type); } } break; case InstanceScope.Singleton: if (item.AsType == null || item.AsType.Length == 0) { cb.Register(item.Type, Reuse.Singleton); } else { foreach (var t in item.AsType) { cb.Register(t, item.Type, Reuse.Singleton); } } break; default: if (item.AsType == null || item.AsType.Length == 0) { cb.Register(item.Type, Reuse.InResolutionScope); } else { foreach (var t in item.AsType) { cb.Register(t, item.Type, Reuse.InResolutionScope); } } break; } } foreach (var item in rb.Instances) { var type = item.AsType ?? item.Instance.GetType(); cb.RegisterInstance(type, item.Instance); } foreach (var it in rb.Funcs) { var item = it; if (item.AsType == null || item.AsType.Length == 0) { throw new NotSupportedException("Result type must be defined. Declared Func result is not defined"); } switch (item.Scope) { case InstanceScope.Transient: foreach (var t in item.AsType) { cb.RegisterDelegate(t, c => item.Func(c.Resolve <IObjectFactory>()), Reuse.Transient); } break; case InstanceScope.Singleton: foreach (var t in item.AsType) { cb.RegisterDelegate(t, c => item.Func(c.Resolve <IObjectFactory>()), Reuse.Singleton); } break; default: foreach (var t in item.AsType) { cb.RegisterDelegate(t, c => item.Func(c.Resolve <IObjectFactory>()), Reuse.InResolutionScope); } break; } } }
internal static void RegisterToContainer(IContainer cb, IObjectFactoryBuilder rb) { foreach (var item in rb.Types) { switch (item.Scope) { case InstanceScope.Transient: if (item.AsType == null || item.AsType.Length == 0) cb.Register(item.Type, Reuse.Transient); else foreach (var t in item.AsType) cb.Register(t, item.Type); break; case InstanceScope.Singleton: if (item.AsType == null || item.AsType.Length == 0) cb.Register(item.Type, Reuse.Singleton); else foreach (var t in item.AsType) cb.Register(t, item.Type, Reuse.Singleton); break; default: if (item.AsType == null || item.AsType.Length == 0) cb.Register(item.Type, Reuse.InResolutionScope); else foreach (var t in item.AsType) cb.Register(t, item.Type, Reuse.InResolutionScope); break; } } foreach (var item in rb.Instances) { var type = item.AsType ?? item.Instance.GetType(); cb.RegisterInstance(type, item.Instance); } foreach (var it in rb.Funcs) { var item = it; if (item.AsType == null || item.AsType.Length == 0) throw new NotSupportedException("Result type must be defined. Declared Func result is not defined"); switch (item.Scope) { case InstanceScope.Transient: foreach (var t in item.AsType) cb.RegisterDelegate(t, c => item.Func(c.Resolve<IObjectFactory>()), Reuse.Transient); break; case InstanceScope.Singleton: foreach (var t in item.AsType) cb.RegisterDelegate(t, c => item.Func(c.Resolve<IObjectFactory>()), Reuse.Singleton); break; default: foreach (var t in item.AsType) cb.RegisterDelegate(t, c => item.Func(c.Resolve<IObjectFactory>()), Reuse.InResolutionScope); break; } } }
public static IObjectFactoryBuilder AddSingleton <TContract>(this IObjectFactoryBuilder builder, TContract instance) { builder.AddSingleton(typeof(TContract), instance); return(builder); }
public static IObjectFactoryBuilder AddSingleton <TContract>(this IObjectFactoryBuilder builder) where TContract : new() { builder.AddSingleton(typeof(TContract), new TContract()); return(builder); }
private static void SetupOracle(IObjectFactoryBuilder builder, string connectionString) { Revenj.DatabasePersistence.Oracle.Setup.ConfigureOracle(builder, connectionString); }
public static void ConfigureProcessing(this IObjectFactoryBuilder builder) { builder.RegisterType <ProcessingEngine, IProcessingEngine>(InstanceScope.Singleton); builder.RegisterType <ScopePool, IScopePool>(InstanceScope.Singleton); }
public void Register(IObjectFactoryBuilder builder) { Contract.Requires(builder != null); }
internal static void RegisterToContainer(ContainerBuilder cb, IObjectFactoryBuilder rb, ConcurrentDictionary<Type, bool> cache) { foreach (var item in rb.Types.Where(i => i.IsGeneric == false)) { if (cache != null) { if (item.AsType != null) foreach (var t in item.AsType) cache.TryAdd(t, true); else cache.TryAdd(item.Type, true); } switch (item.Scope) { case InstanceScope.Transient: if (item.AsType == null || item.AsType.Length == 0) cb.RegisterType(item.Type); else cb.RegisterType(item.Type).As(item.AsType); break; case InstanceScope.Singleton: if (item.AsType == null || item.AsType.Length == 0) cb.RegisterType(item.Type).SingleInstance(); else cb.RegisterType(item.Type).As(item.AsType).SingleInstance(); break; default: if (item.AsType == null || item.AsType.Length == 0) cb.RegisterType(item.Type).InstancePerLifetimeScope(); else cb.RegisterType(item.Type).As(item.AsType).InstancePerLifetimeScope(); break; } } foreach (var item in rb.Types.Where(i => i.IsGeneric)) { if (cache != null) { if (item.AsType != null) foreach (var t in item.AsType) cache.TryAdd(t, true); else cache.TryAdd(item.Type, true); } switch (item.Scope) { case InstanceScope.Transient: if (item.AsType == null || item.AsType.Length == 0) cb.RegisterGeneric(item.Type); else cb.RegisterGeneric(item.Type).As(item.AsType); break; case InstanceScope.Singleton: if (item.AsType == null || item.AsType.Length == 0) cb.RegisterGeneric(item.Type).SingleInstance(); else cb.RegisterGeneric(item.Type).As(item.AsType).SingleInstance(); break; default: if (item.AsType == null || item.AsType.Length == 0) cb.RegisterGeneric(item.Type).InstancePerLifetimeScope(); else cb.RegisterGeneric(item.Type).As(item.AsType).InstancePerLifetimeScope(); break; } } foreach (var item in rb.Instances) { var type = item.AsType ?? item.Instance.GetType(); if (cache != null) cache.TryAdd(type, true); cb.RegisterInstance(item.Instance).As(type); } foreach (var it in rb.Funcs) { var item = it; if (item.AsType == null || item.AsType.Length == 0) throw new NotSupportedException("Result type must be defined. Declared Func result is not defined"); if (cache != null) { foreach (var t in item.AsType) cache.TryAdd(t, true); } switch (item.Scope) { case InstanceScope.Transient: cb.Register(c => item.Func(c.Resolve<IObjectFactory>())).As(item.AsType); break; case InstanceScope.Singleton: cb.Register(c => item.Func(c.Resolve<IObjectFactory>())).As(item.AsType).SingleInstance(); break; default: cb.Register(c => item.Func(c.Resolve<IObjectFactory>())).As(item.AsType).InstancePerLifetimeScope(); break; } } }