private static IDIRegistrator RegisterConfiguration(this IDIRegistrator registrator) { Configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", false) .Build(); return(registrator.Register(p => Configuration, LifetimeType.Singleton)); }
private static IDIRegistrator RegisterAssembly(this IDIRegistrator registrator) => registrator.Register <CollectionHeaderBuilder>(LifetimeType.Singleton) .Register <CollectionItemsBuilder>(LifetimeType.Singleton) .Register(r => new CollectionBuilder(new List <ICollectionPartBuilder> { r.Resolve <CollectionHeaderBuilder>(), r.Resolve <CollectionItemsBuilder>() }), LifetimeType.Singleton) .Register <EnvironmentBuilder>(LifetimeType.Singleton);
private static void RegisterInstanceDescriptors(IDIRegistrator registrator, ServiceDescriptor item, LifetimeType lifetime) { if (item.ServiceType == null) { registrator.Register(item.ImplementationInstance.GetType(), x => item.ImplementationInstance, lifetime); return; } registrator.Register(item.ServiceType, x => item.ImplementationInstance, lifetime); }
public static IDIRegistrator RegisterConfiguration(this IDIRegistrator registrator, Action <IConfiguration>?config = null) { var configuration = JiraTimersConfigurationBuilder.Build(); registrator.Register <IConfiguration>(p => configuration, LifetimeType.Singleton); config?.Invoke(configuration); return(registrator); }
private static void RegisterStandardDescriptors(IDIRegistrator registrator, ServiceDescriptor item, LifetimeType lifetime) { if (item.ImplementationType == null) { registrator.Register(item.ServiceType, lifetime); return; } registrator.Register(item.ServiceType, item.ImplementationType, lifetime); }
private static void RegisterDelegateDescriptors(IDIRegistrator registrator, ServiceDescriptor item, LifetimeType lifetime) { // NOTE: This registration is meaningless cause it registers `object` types //if (item.ServiceType == null) //{ // registrator.Register(x => item.ImplementationFactory(new DIServiceProvider(x)), lifetime); // return; //} registrator.Register(item.ServiceType, x => item.ImplementationFactory(new DIServiceProvider(x)), lifetime); }
public static IDIRegistrator RegisterMyProjectWindowsServiceWithDatabase(this IDIRegistrator registrator) => registrator.Register( r => (MyProjectWindowsServiceWithDatabaseSessionFactoryBuilder) new MyProjectWindowsServiceWithDatabaseSessionFactoryBuilder( r.Resolve <IConfiguration>()).Build(), LifetimeType.Singleton) .Register(r => new MyProjectWindowsServiceWithDatabaseUnitOfWork(r.Resolve <MyProjectWindowsServiceWithDatabaseSessionFactoryBuilder>() .Instance)) .Register <IMyProjectWindowsServiceWithDatabaseUnitOfWork>(r => r.Resolve <MyProjectWindowsServiceWithDatabaseUnitOfWork>()) .Register(r => r.Resolve <MyProjectWindowsServiceWithDatabaseUnitOfWork>().Session) .RegisterTransactRepository <IMyEntity, IMyProjectWindowsServiceWithDatabaseUnitOfWork>() .Register <IMyEntityServiceService, MyEntityService>();
public static IDIRegistrator RegisterDatabase(this IDIRegistrator registrator) => registrator.Register(r => (ExampleSessionFactoryBuilder) new ExampleSessionFactoryBuilder(r.Resolve <IConfiguration>()).Build(), LifetimeType.Singleton) .Register(r => new ExampleUnitOfWork(r.Resolve <ExampleSessionFactoryBuilder>().Instance)) .Register <IExampleUnitOfWork>(r => r.Resolve <ExampleUnitOfWork>()) .Register <IGenericRepository <IUser> >(r => new GenericRepository <IUser>(r.Resolve <ExampleUnitOfWork>().Session)) .Register <UsersService>() .Register <IUsersService>(r => new TransactUsersService(r.Resolve <UsersService>(), r.Resolve <IExampleUnitOfWork>())) .Register <IGenericRepository <ICity> >(r => new GenericRepository <ICity>(r.Resolve <ExampleUnitOfWork>().Session)) .Register <CitiesService>() .Register <ICitiesService>(r => new TransactCitiesService(r.Resolve <CitiesService>(), r.Resolve <IExampleUnitOfWork>()));
public static IDIRegistrator RegisterDatabase(this IDIRegistrator registrator) => registrator.Register(r => new DbContextOptionsBuilder() .UseSqlServer(SettingsBasedConnectionString.Build(r.Resolve <IConfiguration>(), "ExampleDatabaseConnectionSettings")).Options, LifetimeType.Singleton) .Register <ExampleDbContext>() .Register <ExampleUnitOfWork>() .Register <IExampleUnitOfWork>(r => r.Resolve <ExampleUnitOfWork>()) .Register <IGenericRepository <IUser> >(r => new GenericRepository <IUser>(r.Resolve <ExampleUnitOfWork>().Context)) .Register <UsersService>() .Register <IUsersService>(r => new TransactUsersService(r.Resolve <UsersService>(), r.Resolve <IExampleUnitOfWork>())) .Register <IGenericRepository <ICity> >(r => new GenericRepository <ICity>(r.Resolve <ExampleUnitOfWork>().Context)) .Register <CitiesService>() .Register <ICitiesService>(r => new TransactCitiesService(r.Resolve <CitiesService>(), r.Resolve <IExampleUnitOfWork>()));
private static void RegisterServiceDescriptor(IDIRegistrator registrator, ServiceDescriptor item, LifetimeType lifetime) { if (item.ImplementationInstance != null) { RegisterInstanceDescriptors(registrator, item, lifetime); return; } if (item.ImplementationFactory != null) { RegisterDelegateDescriptors(registrator, item, lifetime); return; } RegisterStandardDescriptors(registrator, item, lifetime); }
/// <summary> /// Registers the types from IServiceCollection inside IDIRegistrator (IDIContainerProvider). /// </summary> /// <param name="registrator">The registrator.</param> /// <param name="services">The services collection.</param> /// <exception cref="ArgumentNullException">collection</exception> public static void RegisterFromServiceCollection(this IDIRegistrator registrator, IServiceCollection services) { if (registrator == null) { throw new ArgumentNullException(nameof(registrator)); } if (services == null) { throw new ArgumentNullException(nameof(services)); } foreach (var item in services) { RegisterServiceDescriptor(registrator, item, GetLifetime(item.Lifetime)); } }
public static IDIRegistrator RegisterIts(this IDIRegistrator registrator) { registrator.Register <JiraBasedItsIssuesFactory>(LifetimeType.Singleton) .Register <IItsTrackingIssuesFactory, ItsTrackingIssuesFactory>(LifetimeType.Singleton); registrator.Register <IItsClientFactory, JiraItsClientFactory>(LifetimeType.Singleton) .Register <ItsClientStore>(LifetimeType.Singleton) .Register <IItsClientStore>(r => r.Resolve <ItsClientStore>(), LifetimeType.Singleton); registrator.Register <IItsTrackingIssuesList, ItsTrackingIssuesList>(LifetimeType.Singleton); registrator.Register <IItsIssuesStore>(r => new FileBasedItsIssuesStore(JiraTimersPaths.GetIssuesSettingsFilePath()), LifetimeType.Singleton); registrator.Register <ItsTrackingIssuesListController>(LifetimeType.Singleton) .Register <IItsTrackingIssuesListController>( r => new StateHandlingController(r.Resolve <ItsTrackingIssuesListController>(), r.Resolve <IItsTrackingIssuesList>(), r.Resolve <IItsIssuesStore>()), LifetimeType.Singleton); return(registrator); }
public static IDIRegistrator RegisterConfiguration(this IDIRegistrator registrator) => registrator.Register <IConfiguration>(p => new ConfigurationBuilder() .AddJsonFile("appsettings.json", false) .Build(), LifetimeType.Singleton);
public static IDIRegistrator RegisterCryptography(this IDIRegistrator registrator) => registrator.Register(r => WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7), LifetimeType.Singleton);
public static IDIRegistrator RegisterCryptography(this IDIRegistrator registrator) => registrator.Register(r => WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7), LifetimeType.Singleton) .Register <EncryptionServiceFactory>(LifetimeType.Singleton) .Register(r => WinRTCrypto.CryptographicBuffer, LifetimeType.Singleton);
private static IDIRegistrator RegisterSettings(this IDIRegistrator registrator, IPostmanGenerationSettings?settings) => registrator.Register(r => settings ??= new PostmanGenerationSettings(), LifetimeType.Singleton);
/// <summary> /// Registers the scoped GenericRepository<T> and IGenericRepository<T> as TransactGenericRepository<T> transact repository. /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TUnitOfWork">The type of the unit of work.</typeparam> /// <typeparam name="TUnitOfWorkImpl">The type of the unit of work implementation.</typeparam> /// <param name="registrator">The registrator.</param> /// <param name="isolationLevel">The isolation level.</param> /// <returns></returns> public static IDIRegistrator RegisterTransactRepository <T, TUnitOfWork, TUnitOfWorkImpl>(this IDIRegistrator registrator, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted) where T : class where TUnitOfWork : ITransactUnitOfWork where TUnitOfWorkImpl : UnitOfWork <DbContext> => registrator.Register(r => new GenericRepository <T>(r.Resolve <TUnitOfWorkImpl>().Context)) .Register <IGenericRepository <T> >(r => new TransactGenericRepository <T>(r.Resolve <GenericRepository <T> >(), r.Resolve <TUnitOfWork>(), isolationLevel));
/// <summary> /// Registers the specified service type for resolve with delegate for service implementation instance creation. /// </summary> /// <typeparam name="TService">Service type.</typeparam> /// <param name="registrator">The DI registrator.</param> /// <param name="instanceCreator">The instance creator.</param> /// <param name="lifetimeType">Lifetime type of the registering concrete type.</param> public static IDIRegistrator Register <TService>(this IDIRegistrator registrator, Func <IDIResolver, TService> instanceCreator, LifetimeType lifetimeType = LifetimeType.PerLifetimeScope) where TService : class { return(registrator.Register(typeof(TService), instanceCreator, lifetimeType)); }
/// <summary> /// Registers the scoped StatelessGenericRepository<T> and IGenericRepository<T> as TransactGenericRepository<T> transact repository. /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TUnitOfWork">The type of the unit of work.</typeparam> /// <typeparam name="TUnitOfWorkImpl">The type of the unit of work implementation.</typeparam> /// <param name="registrator">The registrator.</param> /// <param name="isolationLevel">The isolation level.</param> /// <returns></returns> public static IDIRegistrator RegisterStatelessTransactRepository <T, TUnitOfWork, TUnitOfWorkImpl>(this IDIRegistrator registrator, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted) where T : class where TUnitOfWork : ITransactUnitOfWork where TUnitOfWorkImpl : StatelessUnitOfWork => registrator.Register(r => new StatelessGenericRepository <T>(r.Resolve <TUnitOfWorkImpl>().Session)) .Register <IGenericRepository <T> >(r => new TransactGenericRepository <T>(r.Resolve <StatelessGenericRepository <T> >(), r.Resolve <TUnitOfWork>(), isolationLevel));
private static IDIRegistrator RegisterJson(this IDIRegistrator registrator) => registrator.Register <JsonSerializer>(LifetimeType.Singleton);
/// <summary> /// Registers Simplify.Web.Json JsonModelBinder. /// </summary> /// <param name="registrator">The registrator.</param> public static IDIRegistrator RegisterHttpMultipartFormModelBinder(this IDIRegistrator registrator) => registrator.Register <HttpMultipartFormModelBinder>(LifetimeType.Singleton);
public static IDIRegistrator RegisterQt(this IDIRegistrator registrator, string[] args) => registrator.Register(r => new QGuiApplication(args), LifetimeType.Singleton) .Register <QQmlApplicationEngine>(LifetimeType.Singleton);
/// <summary> /// Registers the specified concrete type for resolve. /// </summary> /// <param name="registrator">The DI registrator.</param> /// <param name="concreteType">Concrete type.</param> /// <param name="lifetimeType">Lifetime type of the registering concrete type.</param> public static IDIRegistrator Register(this IDIRegistrator registrator, Type concreteType, LifetimeType lifetimeType = LifetimeType.PerLifetimeScope) { return(registrator.Register(concreteType, concreteType, lifetimeType)); }
/// <summary> /// Registers Simplify.Web.Json JsonModelBinder which will search for `JsonSerializerSettings` registered in container (JsonSerializerSettings should be manually registered in container). /// </summary> /// <param name="registrator">The registrator.</param> /// <returns></returns> public static IDIRegistrator RegisterJsonModelBinderWithSettingsFromContainer(this IDIRegistrator registrator) => registrator.Register(r => new JsonModelBinder(r.Resolve <JsonSerializerSettings>()), LifetimeType.Singleton);
/// <summary> /// Registers the specified concrete type for resolve. /// </summary> /// <typeparam name="TConcrete">Concrete type.</typeparam> /// <param name="registrator">The DI registrator.</param> /// <param name="lifetimeType">Lifetime type of the registering concrete type.</param> public static IDIRegistrator Register <TConcrete>(this IDIRegistrator registrator, LifetimeType lifetimeType = LifetimeType.PerLifetimeScope) where TConcrete : class { return(registrator.Register(typeof(TConcrete), typeof(TConcrete), lifetimeType)); }
/// <summary> /// Registers Simplify.Web.Json JsonModelBinder. /// </summary> /// <param name="registrator">The registrator.</param> /// <param name="settings">The settings.</param> /// <returns></returns> public static IDIRegistrator RegisterJsonModelBinder(this IDIRegistrator registrator, JsonSerializerSettings?settings = null) => registrator.Register(r => new JsonModelBinder(settings), LifetimeType.Singleton);
/// <summary> /// Registers the specified service type with corresponding implementation type. /// </summary> /// <typeparam name="TService">Service type.</typeparam> /// <typeparam name="TImplementation">Implementation type.</typeparam> /// <param name="registrator">The DI registrator.</param> /// <param name="lifetimeType">Lifetime type of the registering service type.</param> public static IDIRegistrator Register <TService, TImplementation>(this IDIRegistrator registrator, LifetimeType lifetimeType = LifetimeType.PerLifetimeScope) { return(registrator.Register(typeof(TService), typeof(TImplementation), lifetimeType)); }
/// <summary> /// Registers the specified service type with corresponding implementation type. /// </summary> /// <typeparam name="TService">Service type.</typeparam> /// <param name="registrator">The DI registrator.</param> /// <param name="implementationType">Implementation type.</param> /// <param name="lifetimeType">Lifetime type of the registering service type.</param> public static void Register <TService>(this IDIRegistrator registrator, Type implementationType, LifetimeType lifetimeType = LifetimeType.PerLifetimeScope) { registrator.Register(typeof(TService), implementationType, lifetimeType); }
public static IDIRegistrator RegisterInfrastructure(this IDIRegistrator registrator) => registrator.Register <INotifier, ConsoleNotifier>(LifetimeType.Singleton) .Register <IUserDisplayer, ConsoleUserDisplayer>() .Register <ArgsVerifier>(LifetimeType.Singleton) .Register <ArgsHandler>();
public static IDIRegistrator RegisterJiraTimersSettings(this IDIRegistrator registrator) => registrator.Register <CacheableSettings>(LifetimeType.Singleton) .Register <ISettings>(r => r.Resolve <CacheableSettings>(), LifetimeType.Singleton);