Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy(AllowAllSpecificOrigins,
                                  builder =>
                {
                    builder
                    .AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });

            services.AddControllers();

            // TODO: convention based
            var appInfoOptions = new ApplicationInfoOptions();

            Configuration.GetSection(ApplicationInfoOptions.SectionName).Bind(appInfoOptions);
            services.AddSingleton(appInfoOptions);

            var lyricsApiOptions = new LyricsApiOptions();

            Configuration.GetSection(LyricsApiOptions.SectionName).Bind(lyricsApiOptions);
            services.AddSingleton(lyricsApiOptions);

            services.AddTransient <IArtistService, MusicBrainzService>();
            services.AddTransient <ILyricsService, LyricsService>();
            services.AddTransient <IWordCounterService, WordCounterService>();
            services.AddTransient <IAggregatorProcess, AggregatorProcess>();

            services.AddSingleton(new HttpClient());
            services.AddSingleton <ICacheService, CacheService>();
        }
Ejemplo n.º 2
0
        public MusicBrainzService(ApplicationInfoOptions options)
        {
            options = options ?? throw new ArgumentNullException(nameof(options));

            Query.DefaultUserAgent = $"{options.Name}/{options.Version} ( {options.ContactEmail} )";
        }