Exemple #1
0
        public void Configuration(IAppBuilder app)
        {
            GlobalConfiguration.Configure(config =>
            {
                var container             = UnityConfiguration.GetContainer();
                config.DependencyResolver = new UnityDependencyResolver(container);
                ApiConfiguration.Install(config, app);

                var client = SubscriptionClient.CreateFromConnectionString(CoreConfiguration.Config.EventQueueConnectionString, CoreConfiguration.Config.TopicName, CoreConfiguration.Config.SubscriptionName);

                var accountsEventBusMessageHandler      = container.Resolve <Features.Accounts.IAccountsEventBusMessageHandler>();
                var digitalAssetsEventBusMessageHandler = container.Resolve <Features.DigitalAssets.IDigitalAssetsEventBusMessageHandler>();
                var featuresEventBusMessageHandler      = container.Resolve <Features.Features.IFeaturesEventBusMessageHandler>();
                var profilesEventBusMessageHandler      = container.Resolve <Features.Profiles.IProfilesEventBusMessageHandler>();
                var subscriptionsEventBusMessageHandler = container.Resolve <Features.Subscriptions.ISubscriptionsEventBusMessageHandler>();
                var tenantsEventBusMessageHandler       = container.Resolve <Features.Tenants.ITenantsEventBusMessageHandler>();
                var usersEventBusMessageHandler         = container.Resolve <Features.Users.IUsersEventBusMessageHandler>();

                client.OnMessage(message =>
                {
                    try
                    {
                        var messageBody       = ((BrokeredMessage)message).GetBody <string>();
                        var messageBodyObject = DeserializeObject <JObject>(messageBody, new JsonSerializerSettings
                        {
                            ReferenceLoopHandling      = ReferenceLoopHandling.Serialize,
                            PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                            TypeNameHandling           = TypeNameHandling.All,
                            ContractResolver           = new CamelCasePropertyNamesContractResolver()
                        });

                        accountsEventBusMessageHandler.Handle(messageBodyObject);
                        digitalAssetsEventBusMessageHandler.Handle(messageBodyObject);
                        featuresEventBusMessageHandler.Handle(messageBodyObject);
                        profilesEventBusMessageHandler.Handle(messageBodyObject);
                        subscriptionsEventBusMessageHandler.Handle(messageBodyObject);
                        tenantsEventBusMessageHandler.Handle(messageBodyObject);
                        usersEventBusMessageHandler.Handle(messageBodyObject);
                    }
                    catch (Exception e)
                    {
                    }
                });
            });
        }
Exemple #2
0
        public static void Install(HttpConfiguration config, IAppBuilder app)
        {
            WebApiUnityActionFilterProvider.RegisterFilterProviders(config);
            var container = GetContainer();

            app.MapSignalR();

            app.Use(typeof(StatusMiddleware));

            config.Filters.Add(new HandleErrorAttribute(container.Resolve <ILoggerFactory>()));

            app.UseCors(CorsOptions.AllowAll);

            config.SuppressHostPrincipal();

            var mediator = container.Resolve <IMediator>();
            Lazy <IAuthConfiguration> lazyAuthConfiguration = UnityConfiguration.GetContainer().Resolve <Lazy <IAuthConfiguration> >();

            config.EnableSwagger(c => {
                c.UseFullTypeNameInSchemaIds();
                c.SingleApiVersion("v1", "IdentityService");
            })
            .EnableSwaggerUi();

            app.UseOAuthAuthorizationServer(new OAuthOptions(lazyAuthConfiguration, mediator));

            app.UseJwtBearerAuthentication(new JwtOptions(lazyAuthConfiguration));

            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            config.Filters.Add(new System.Web.Http.AuthorizeAttribute());

            var jSettings = new JsonSerializerSettings();

            jSettings.Formatting            = Formatting.Indented;
            jSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            jSettings.ContractResolver      = new SignalRContractResolver();
            config.Formatters.JsonFormatter.SerializerSettings = jSettings;

            config.Formatters.Remove(config.Formatters.XmlFormatter);

            GlobalHost.DependencyResolver.Register(typeof(JsonSerializer), () => JsonSerializer.Create(jSettings));

            config.MapHttpAttributeRoutes();
        }