예제 #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            Startup.AddIndexerServices(services, Configuration);

            services.Replace(new ServiceDescriptor(typeof(IMapMongoBlockToStorageBlock), typeof(CirrusBlockMapping),
                                                   ServiceLifetime.Transient));

            services.Replace(new ServiceDescriptor(typeof(ICryptoClientFactory), typeof(CirrusClientFactory),
                                                   ServiceLifetime.Singleton));

            ServiceDescriptor descriptor = services.First(_ => _.ImplementationType == typeof(MongoBuilder));

            services.Remove(descriptor);
            services.AddSingleton <TaskStarter, CirrusMongoBuilder>();

            services.Replace(new ServiceDescriptor(typeof(ISyncBlockTransactionOperationBuilder), typeof(CirrusSyncBlockTransactionOperationBuilder),
                                                   ServiceLifetime.Singleton));

            services.Replace(new ServiceDescriptor(typeof(IScriptInterpeter), typeof(CirrusScriptToAddressParser), ServiceLifetime.Singleton));

            services.Replace(new ServiceDescriptor(typeof(IStorageOperations), typeof(CirrusMongoStorageOperations), ServiceLifetime.Singleton));

            services.Replace(new ServiceDescriptor(typeof(IStorage), typeof(CirrusMongoData), ServiceLifetime.Singleton));

            services.AddSingleton <ICirrusStorage, CirrusMongoData>();
            services.AddSingleton <ICirrusMongoDb, CirrusMongoDb>();

            services.AddControllers()
            .AddApplicationPart(typeof(Startup).Assembly)
            .AddControllersAsServices();

            services.AddTransient <IComputeSmartContractService <NonFungibleTokenComputedTable>, NftComputationService>();
            services.AddTransient(typeof(IComputeSmartContractService <>), typeof(ComputeSmartContractService <>));
            services.AddTransient(typeof(ISmartContractHandlersFactory <>), typeof(SmartContractHandlersFactory <>));

            ScanAssemblyAndRegisterTypeByNameAsTransient(services, typeof(ILogReader <DaoContractComputedTable>),
                                                         typeof(ILogReader <>).Assembly);
            ScanAssemblyAndRegisterTypeByNameAsTransient(services, typeof(ILogReader <StandardTokenComputedTable>),
                                                         typeof(ILogReader <>).Assembly);
            ScanAssemblyAndRegisterTypeByNameAsTransient(services, typeof(ILogReader <NonFungibleTokenComputedTable>),
                                                         typeof(ILogReader <>).Assembly);

            RegisterSmartContractBuilder(services); //No need to scan the assembly as there won't be that many
        }