Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time

using System;
using Autofac;
using Autofac.Extensions.DependencyInjection;
using Identity.Api.Messaging.Consumers;
using Identity.Api.Models;
using Identity.Api.Services;
using MassTransit;
using MassTransit.Util;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using StackExchange.Redis;
namespace Identity.Api
public class Startup
public Startup(IConfiguration configuration)
Configuration = configuration;
public IContainer ApplicationContainer { get; private set; }
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
//By connecting here we are making sure that our service
//cannot start until redis is ready. This might slow down startup,
//but given that there is a delay on resolving the ip address
//and then creating the connection it seems reasonable to move
//that cost to startup instead of having the first request pay the
services.AddSingleton(sp =>
var configuration = new ConfigurationOptions {ResolveDns = true};
return ConnectionMultiplexer.Connect(configuration);
services.AddTransient<IIdentityRepository, IdentityRepository>();
var builder = new ContainerBuilder();
// register a specific consumer
builder.Register(context =>
var busControl = Bus.Factory.CreateUsingRabbitMq(cfg =>
var host = cfg.Host(new Uri("rabbitmq://rabbitmq/"), h =>
cfg.ReceiveEndpoint(host, "dotnetgigs" + Guid.NewGuid().ToString(), e =>
return busControl;
ApplicationContainer = builder.Build();
return new AutofacServiceProvider(ApplicationContainer);
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public async void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider, IApplicationLifetime lifetime)
if (env.IsDevelopment())
// stash an applicant's user data in redis for test purposes...this would simulate establishing auth/session in the real world
var identityRepository=serviceProvider.GetService<IIdentityRepository>();
await identityRepository.UpdateUserAsync(new User {Id = "1", Email = "",Name = "Josh Dillinger"});
var bus = ApplicationContainer.Resolve<IBusControl>();
var busHandle = TaskUtil.Await(() => bus.StartAsync());
lifetime.ApplicationStopping.Register(() => busHandle.Stop());