Example #1
0
        public void GetPlayerFromEvents()
        {
            var playerId = new Guid("06ba848f-9a28-4b44-af15-e42fabec93b7");
            var repo = new EventStoreRepository();
            repo.Connect();
            var user = new PlayerByEvents(repo).Execute(playerId);
            repo.Close();

            Console.WriteLine(new JsonSerializer().Serialize(user));
        }
Example #2
0
        public void Configuration(IAppBuilder app)
        {
            //JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();

            //app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions()
            //{
            //    Authority = _configManager.Get("Authentication.Authority"),
            //    RequiredScopes = _configManager.Get("Authentication.Scopes").Split(',')
            //});

            // Auth 0
            var issuer = "https://" + _configManager.Get("auth0.Domain") + "/";
            var audience = _configManager.Get("auth0.ClientId");
            var secret = TextEncodings.Base64.Encode(TextEncodings.Base64Url.Decode(_configManager.Get("auth0.ClientSecret")));

            //app.use
            string token = string.Empty;
            app.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions()
            {
                AuthenticationMode = AuthenticationMode.Active,
                AllowedAudiences = new[] { audience},
                IssuerSecurityTokenProviders = new[]
                {
                    new SymmetricKeyIssuerSecurityTokenProvider(issuer, secret)
                }

            });

            var container = new Container();
            container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();

            var bus = new MassTransitBus();
            container.Register<IBus>(() => bus, Lifestyle.Singleton);

            var eventStoreRepo = new EventStoreRepository();
            //eventStoreRepo.Connect();

            var logger = new SerilogLogger();
            container.Register<IEventStoreRepository>(() => eventStoreRepo, Lifestyle.Singleton);
            container.Register<IMarkerService, MarkerService>(Lifestyle.Scoped);
            container.Register<IGearService, GearService>(Lifestyle.Scoped);
            container.Register<ILoadoutService, LoadoutService>(Lifestyle.Scoped);
            container.Register<IUserService, PlayerService>(Lifestyle.Scoped);
            container.Register<IRankService, RankService>(Lifestyle.Scoped);
            container.Register<ITeamService, TeamService>(Lifestyle.Scoped);
            container.Register<INotificationService, NotificationService>(Lifestyle.Scoped);
            container.Register<ILogger>(() => logger, Lifestyle.Singleton);
            container.Register<ICopier, NewtonsoftCopier>(Lifestyle.Singleton);
            container.Register<ILogEventBuilder, BaseLogEventBuilder>(Lifestyle.Singleton);
            container.Register<PB.Infrastructure.Interfaces.IComparer, KellermanComparer>(Lifestyle.Singleton);

            try
            {
                container.Verify();
            }
            catch (Exception ex)
            {
                logger.Fatal(ex);
                throw;
            }

            var config = new WebApiConfig();
            config.Services.Replace(typeof(IExceptionHandler), new MyExceptionHandler(logger));
            config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
            config.Filters.Add(new ActionExecutedPerformanceFilter(logger));
            config.MessageHandlers.Add(new ApiThrottlingHandler()
            {
                Policy = new ThrottlePolicy(perSecond: 5)
                {
                    ClientThrottling = true
                },
                Repository = new CacheRepository(),
                Logger = new ApiThrottleLogger(logger)
            });

            app.UseWebApi(config);

            AutoMapperMappings.Map();
        }