public ApplicationBaseFixture() { var configurationBuilder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true); Configuration = configurationBuilder.Build(); Repository = new CommRepository(StorageAccount.NewFromConnectionString(Configuration["Values:AzureWebJobsStorage"])); App = new App(Repository); }
public void Configure(IWebJobsBuilder builder) { // Populates the Autofac container builder with the set of registered service descriptors DependencyInjection.Initialize( cfg => { cfg.Populate(builder.Services); var serviceProvider = builder.Services.BuildServiceProvider(); var storageAccount = serviceProvider.GetService <StorageAccountProvider>().GetHost(); var repository = new CommRepository(storageAccount); repository.CreateStorageIfNotExists().ConfigureAwait(false); cfg.Register(context => repository); }, Name ); }
public IServiceProvider ConfigureServices(IServiceCollection services) { // Create an Autofac Container and push the framework services var containerBuilder = new ContainerBuilder(); containerBuilder.Populate(services); containerBuilder.RegisterModule(new CommonModule()); // Register your own services within Autofac var storageAccount = services.BuildServiceProvider().GetService <StorageAccountProvider>().GetHost(); var repository = new CommRepository(storageAccount); repository.CreateStorageIfNotExists().ConfigureAwait(false); containerBuilder.RegisterInstance(repository).As <ICommRepository>().As <IQueueRepository>().As <ITableRepository>().As <IBlobRepository>(); containerBuilder.RegisterType <App>().SingleInstance().AsSelf(); // Build the container and return an IServiceProvider from Autofac var container = containerBuilder.Build(); var serviceProvider = container.Resolve <IServiceProvider>(); return(serviceProvider); }