Пример #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var config = new ServerConfig();

            Configuration.Bind(config);

            var libraryContext = new RemoteLibraryContext(config.MongoDB);

            var booksRepository   = new BooksRepository(libraryContext);
            var writersRepository = new WritersRepository(libraryContext);


            services.AddSingleton <IBooksRepository>(booksRepository);
            services.AddSingleton <IWritersRepository>(writersRepository);

            //services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
            //services.AddScoped<IUrlHelper>(factory =>
            //{
            //   var actionContext = factory.GetService<IActionContextAccessor>()
            //                                  .ActionContext;
            //   return new UrlHelper(actionContext);
            //});

            services.AddControllers();
        }
Пример #2
0
 public WritersRepository(RemoteLibraryContext context)
 {
     libraryContext = context;
 }
Пример #3
0
 public BooksRepository(RemoteLibraryContext context)
 {
     libraryContext = context;
 }