Skip to content

Commit

Permalink
Migrate Startup and drop duplicate container registration code
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreb committed Dec 4, 2022
1 parent 06d3c8a commit f503639
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 265 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MongoDB.Driver" Version="2.14.1" />
<PackageReference Include="MongoDB.Driver" Version="2.18.0" />
<PackageReference Include="Moq" Version="4.17.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
Expand Down
31 changes: 1 addition & 30 deletions src/Blockcore.Indexer.Cirrus/CirrusStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public void ConfigureServices(IServiceCollection services)
services.AddTransient<ISmartContractTransactionsLookup<NonFungibleTokenContractTable>,NonFungibleTokenSmartContractTransactionsLookup>();
services.AddTransient(typeof(ISmartContractTransactionsLookup<>), typeof(SmartContractTransactionsLookup<>));



ScanAssemblyAndRegisterTypeByNameAsTransient(services, typeof(ILogReader<DaoContractTable,DaoContractProposalTable>),
typeof(ILogReader<DaoContractTable,DaoContractProposalTable>).Assembly);
ScanAssemblyAndRegisterTypeByNameAsTransient(services, typeof(ILogReader<StandardTokenContractTable,StandardTokenHolderTable>),
Expand Down Expand Up @@ -117,34 +115,7 @@ where type.GetInterface(typeToRegister.Name) != null &&

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseExceptionHandler("/error");

// Enable Cors
app.UseCors("IndexerPolicy");

app.UseResponseCompression();

app.UseDefaultFiles();

app.UseStaticFiles();

app.UseRouting();

app.UseSwagger(c =>
{
c.RouteTemplate = "docs/{documentName}/openapi.json";
});

app.UseSwaggerUI(c =>
{
c.RoutePrefix = "docs";
c.SwaggerEndpoint("/docs/indexer/openapi.json", "Blockcore Indexer API");
});

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
Startup.Configure(app, env);
}
}
}
2 changes: 1 addition & 1 deletion src/Blockcore.Indexer.Core/Blockcore.Indexer.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
<PackageReference Include="MongoDB.Driver" Version="2.14.1" />
<PackageReference Include="MongoDB.Driver" Version="2.18.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.3.1" />
Expand Down
19 changes: 5 additions & 14 deletions src/Blockcore.Indexer.Core/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ namespace Blockcore.Indexer.Core
{
public class Startup
{
public IConfiguration Configuration { get; }

public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public void ConfigureServices(IServiceCollection services)
{
AddIndexerServices(services, Configuration);
}

public static void AddIndexerServices(IServiceCollection services, IConfiguration configuration)
{
services.Configure<ChainSettings>(configuration.GetSection("Chain"));
Expand Down Expand Up @@ -94,9 +82,9 @@ public static void AddIndexerServices(IServiceCollection services, IConfiguratio
services.AddScoped<TaskStarter, BlockStartup>();

services.AddScoped<TaskRunner, BlockIndexer>();

services.AddScoped<TaskRunner, RichListSync>();

// TODO: Verify that it is OK we add this to shared Startup for Blockcore and Cirrus.
services.AddScoped<TaskRunner, HistoryComputer>();
services.AddSingleton<IComputeHistoryQueue, ComputeHistoryQueue>();

Expand Down Expand Up @@ -157,9 +145,12 @@ public static void AddIndexerServices(IServiceCollection services, IConfiguratio
services.AddTransient<IMapMongoBlockToStorageBlock, MapMongoBlockToStorageBlock>();
services.AddSingleton<ICryptoClientFactory, CryptoClientFactory>();
services.AddSingleton<ISyncBlockTransactionOperationBuilder, SyncBlockTransactionOperationBuilder>();

// TODO: Verify that it is OK we add this to shared Startup for Blockcore and Cirrus.
services.AddTransient<IBlockRewindOperation, BlockRewindOperation>();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseExceptionHandler("/error");

Expand Down
7 changes: 5 additions & 2 deletions src/Blockcore.Indexer.Core/Sync/ComputeHistoryQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ public ComputeHistoryQueue(IOptions<IndexerSettings> indexerSettings)

public void AddAddressToComputeHistoryQueue(string address)
{
if (indexerSettings.MaxItemsInHistoryQueue <= 0 ||
collection.Count >= indexerSettings.MaxItemsInHistoryQueue)
if (indexerSettings.MaxItemsInHistoryQueue <= 0 || collection.Count >= indexerSettings.MaxItemsInHistoryQueue)
{
return;
}

if (!collection.Contains(address))
{
collection.Enqueue(address);
}
}

public bool GetNextItemFromQueue(out string address)
Expand Down
28 changes: 28 additions & 0 deletions src/Blockcore.Indexer/BlockcoreStartup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Blockcore.Indexer.Core;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Blockcore.Indexer
{
public class BlockcoreStartup
{
public IConfiguration Configuration { get; }

public BlockcoreStartup(IConfiguration configuration)
{
Configuration = configuration;
}

public void ConfigureServices(IServiceCollection services)
{
Startup.AddIndexerServices(services, Configuration);
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
Startup.Configure(app, env);
}
}
}
2 changes: 1 addition & 1 deletion src/Blockcore.Indexer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
serverOptions.AddServerHeader = false;
});

webBuilder.UseStartup<Startup>();
webBuilder.UseStartup<BlockcoreStartup>();
});
}
}
216 changes: 0 additions & 216 deletions src/Blockcore.Indexer/Startup.cs

This file was deleted.

0 comments on commit f503639

Please sign in to comment.