Exemplo n.º 1
0
        static void RegisterServices(IAbstractDependencyInjector di)
        {
            // Microsoft.Extensions.Configuration.IConfigurationRoot
            // Microsoft.Extensions.Configuration.IConfiguration
            //var ss = typeof(Configuration).Name;

            // Add services here.
            di.AddSingletone(Configuration);
            //di.AddPerThread<IMediaDataContext, MediaDataContext>();
            di.AddPerThread <itest, test>();

            di.Build();
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication("MyAuth")
            .AddScheme <MyAuthSchemeOptions, MyAuthenticationHandler>("MyAuth", options => {
                var authSettings = _di.Resolve <IOptions <AuthSettings> >().Value;
                options.Scheme   = "MyAuth";
                options.AccessTokenKeyHeaderName  = authSettings.AccessTokenHeaderName;
                options.SessionInfoContextKeyName = authSettings.SessionInfoContextKeyName;
                options.Expiration = new TimeSpan((authSettings.ExpirationInMin - authSettings.ExpirationInMin % 60) / 60,
                                                  authSettings.ExpirationInMin % 60, 0);
            });

            services.AddMvc();
            services.AddMemoryCache();

            // Configure settings.
            services.AddOptions();
            services.Configure <GoogleDriveSettings>(_configuration.GetSection("MediaStorage:GoogleDrive"));
            services.Configure <LocalDriveSettings>(_configuration.GetSection("MediaStorage:Local"));
            services.Configure <AuthSettings>(_configuration.GetSection("Auth"));

            // Configure dependency abstructor.
            _di = services.UseMicrosoftDI(_serviceProvider);
            _di.AddSingletone(_configuration);
            _di.AddSingletone(_di);
            _di.AddPerThread <AuthenticationHandler <MyAuthSchemeOptions>, MyAuthenticationHandler>();

            // Start registering services.
            _di.RegisterStorageServices(_hostingEnvironment);
            _di.RegisterMediaDataContextServices();
            _di.RegisterStreamingDataContextServices();
            _di.RegisterCoreServices();
            // End registering services.

            return(_di.Build());
        }