示例#1
0
        static async Task Main(string[] args)
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json", true, true)
                                    .Build();

            config = DependencyBootstrapper.AddSecrets(config);

            var services = new ServiceCollection();

            DependencyBootstrapper.ConfigureDependencies(services, config);

            var provider = services.BuildServiceProvider();

            var context = provider.GetService <MusicLibraryContext>();

            var libMan       = provider.GetService <LibraryService>();
            var saveWorkflow = new SaveNewFilesToDatabaseWorkflow(libMan);

            foreach (var path in args)
            {
                await saveWorkflow.Execute(path);
            }

            var uploadWorkflow = new UploadFilesToAzureWorkflow(context, provider.GetService <IDriveServiceFactory>(), libMan);
            await uploadWorkflow.Execute();
        }
示例#2
0
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage
        static void Main()
        {
            var container    = new UnityContainer();
            var bootstrapper = new DependencyBootstrapper();

            bootstrapper.Configure(container);
            var activator = new UnityJobActivator(container);
            var host      = new JobHost(new JobHostConfiguration {
                JobActivator = activator
            });

            // The following code ensures that the WebJob will be running continuously
            host.RunAndBlock();
        }
示例#3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                Configuration = DependencyBootstrapper.AddSecrets(Configuration);
            }

            app.UseRouting();
            app.UseCors("enable-all");

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
示例#4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public virtual IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();


            var builder = new ContainerBuilder();

            builder.RegisterType <HttpJsonProxy>();
            builder.RegisterType <HttpJsonProxyGeneratorInterceptor>();


            var registeredTypes = new List <Type>();

            DependencyBootstrapper.Scan(_assemblies, (i, t) =>
            {
                builder.RegisterType(t).As(i);
                registeredTypes.Add(i);
            });



            var sb = new ServiceBootstrapper();

            sb.Scan(_assemblies, registeredTypes);
            sb.UnmatchedInterfaces.Values.ToList().ForEach(v =>
            {
                v.ForEach(t =>
                {
                    builder.RegisterInstance(GenerateProxy(t)).As(t)
                    //.AsImplementedInterfaces()
                    //.InstancePerLifetimeScope()
                    .EnableInterfaceInterceptors()
                    .InterceptedBy(typeof(HttpJsonProxyGeneratorInterceptor));
                });
            });

            builder.Populate(services);
            ApplicationContainer = builder.Build();
            var sp = new AutofacServiceProvider(ApplicationContainer);

            return(sp);
        }
示例#5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            var appSettingsSection = Configuration.GetSection("AppSettings");
            // services.Configure<AppSettings>(appSettingsSection);

            var appSettings = appSettingsSection.Get <AppSettings>();
            var key         = Encoding.ASCII.GetBytes(appSettings.TokenSecret);

            services.AddSingleton <IJwtTokenProviderService, GoogleTokenProviderService>(provider => new GoogleTokenProviderService(
                                                                                             appSettings.TokenSecret,
                                                                                             appSettings.GoogleClientId,
                                                                                             appSettings.GoogleClientSecret,
                                                                                             provider.GetService <MusicLibraryContext>()));

            DependencyBootstrapper.ConfigureDependencies(services, Configuration);

            services.AddCors(b => b.AddPolicy("enable-all", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()));

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            });

            services.AddAuthentication().AddJwtBearer(o =>
            {
                o.RequireHttpsMetadata      = false;
                o.SaveToken                 = true;
                o.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });
        }
示例#6
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Configure Web API to use only bearer token authentication.
            //config.SuppressDefaultHostAuthentication();
            //config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            DependencyBootstrapper.EnsureDependenciesRegistered();

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            config.Routes.MapHttpRoute(
                "ActionApi",
                "api/{controller}/{action}/{id}",
                new { id = RouteParameter.Optional }
                );
        }
示例#7
0
 public static void Initialize(TestContext testContext)
 {
     DependencyBootstrapper.EnsureDependenciesRegistered();
 }
示例#8
0
 protected override void PerformAction()
 {
     OnExecuting(DependencyBootstrapper.BeginLifetimeScope());
 }