public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSingleton <ISyndFeedStore>(container => { var bucketId = Configuration["Amathus:BucketId"]; var logger = container.GetRequiredService <ILogger <ISyndFeedStore> >(); return(new CloudStorageSyndFeedStore(bucketId, logger)); }); _sources = Configuration.GetSection("Amathus:Sources").Get <List <Source> >(); services.AddSingleton <IFeedConverter>(container => { var logger = container.GetRequiredService <ILogger <IFeedConverter> >(); return(new FeedConverter(_sources, logger)); }); _backend = Enum.Parse <FeedStoreBackend>(Configuration["Amathus:FeedStore"], ignoreCase: true); switch (_backend) { case FeedStoreBackend.Firestore: services.AddSingleton <IFeedStore>(provider => new FirestoreFeedStore( Configuration["Amathus:ProjectId"])); break; default: throw new ArgumentException("Backend cannot be initialized"); } }
public void ConfigureServices(IServiceCollection services) { // Enable Cors. You can test by running this in console: // fetch('<replace with service url>', ()=> {debugger}); services.AddCors(options => { options.AddPolicy("MyPolicy", policyBuilder => { policyBuilder.AllowAnyHeader(); policyBuilder.AllowAnyMethod(); policyBuilder.AllowAnyOrigin(); }); }); services.AddControllers() .AddNewtonsoftJson(options => { // To get upper case in Json options.SerializerSettings.ContractResolver = new DefaultContractResolver(); }); _backend = Enum.Parse <FeedStoreBackend>(Configuration["Amathus:FeedStore"], ignoreCase: true); switch (_backend) { // InMemory is for local testing. When it's used, it sets up a // an local hosted service that reads the feeds and saves into // memory. case FeedStoreBackend.InMemory: services.AddSingleton <IFeedStore, InMemoryFeedStore>(); services.AddHostedService <FeedReaderService>(); _sources = Configuration.GetSection("Amathus:Sources").Get <List <Source> >(); services.AddSingleton <IFeedReader>(container => { var logger = container.GetRequiredService <ILogger <IFeedReader> >(); return(new FeedReader(_sources, logger)); }); services.AddSingleton <IFeedConverter>(container => { var logger = container.GetRequiredService <ILogger <IFeedConverter> >(); return(new FeedConverter(_sources, logger)); }); break; // Firestore backedend. It assumes that the backend is already populated. case FeedStoreBackend.Firestore: services.AddSingleton <IFeedStore>(provider => new FirestoreFeedStore( Configuration["Amathus:ProjectId"])); break; default: throw new ArgumentException("Backend cannot be initialized"); } }