Exemplo n.º 1
0
        static public void Configure(IServiceCollection serviceCollection)
        {
            //TODO: add interfaces for some of these
            serviceCollection.AddSingleton <SuspendAndResumeService>();
            serviceCollection.AddSingleton <CommandLineActivationHandler>();

            serviceCollection.AddHttpClient(Options.DefaultName, (client) => { client.BaseAddress = new Uri(Secrets.ServerUrl); });

            serviceCollection.AddSingleton <HttpClient>((provider) => provider.GetService <IHttpClientFactory>().CreateClient());

            serviceCollection.AddSingleton <ILogger>((_) => LoggingFactory.BuildLogger());

            // Only ever have one player in the application
            serviceCollection.AddSingleton <PlayerViewModel>();

            serviceCollection.AddSingleton <ServerCaller>();

            //serviceCollection.AddSingleton((provider) => new ServerCaller(provider.GetService<IHttpClientFactory>().CreateClient()));

            string dbPath = FileHelper.GetLibraryDbPath();

            serviceCollection.AddSingleton <SqliteConnection>((_) => SQLiteHelpers.CreateFileDb(dbPath));

            serviceCollection.AddSingleton <Library>();

            //serviceCollection.AddSingleton((provider) => new Library(Environment.MachineName, SQLiteHelpers.CreateFileDb(dbPath),
            //    provider.GetService<ServerCaller>(), provider.GetService<ILogger>()));

            //serviceCollection.AddScoped<ICommonServices, CommonServices>();
            //serviceCollection.AddTransient<LoginViewModel>();

            _rootServiceProvider = serviceCollection.BuildServiceProvider();
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddSingleton <ISerializedEventRepository, SQLiteEventRepository>(
                _ => new SQLiteEventRepository(SQLiteHelpers.CreateFileDb(Paths.LibraryDbPath)));

            services.AddTransient <IClock, Clock>();

            services.AddTransient <LibraryItemEventFactory>();
        }