예제 #1
0
 public static IServiceRegistrar AddMessaging(this IServiceCollection services,
                                              Profile profile,
                                              EndpointBindings bindings,
                                              params Assembly[] messageAndHandlerAssemblies)
 {
     return(AddMessaging(services, profile, bindings, null, messageAndHandlerAssemblies));
 }
예제 #2
0
        public static IServiceRegistrar AddMessaging(this IServiceCollection services,
                                                     Profile profile,
                                                     EndpointBindings bindings,
                                                     Action <MessagingConfiguration> config,
                                                     params Assembly[] messageAndHandlerAssemblies)
        {
            MessagingService.InitializeTypes(messageAndHandlerAssemblies);
            if (bindings != null)
            {
                profile.AddBindings(bindings);
            }
            var messagingConfig = new MessagingConfiguration();

            if (config != null)
            {
                config.Invoke(messagingConfig);
            }

            services.AddSingleton(messagingConfig);
            services.AddTransient <IServiceFactory>(x => new MicrosoftDependencyInjectionServiceFactory(x));
            services.AddSingleton(profile);
            services.AddSingleton <MessagingService>();
            services.AddTransient <IMessagingClient, MessagingClient>();

            //setup user message handlers
            services.Scan(c =>
            {
                c.FromAssemblies(messageAndHandlerAssemblies)
                .AddClasses(t => t.AssignableTo(typeof(IMessageHandler <>)))
                .AsImplementedInterfaces()
                .WithTransientLifetime()
                .AddClasses(t => t.AssignableTo(typeof(ICustomMessageHandler <>)))
                .AsImplementedInterfaces()
                .WithTransientLifetime()
                .AddClasses(t => t.AssignableTo(typeof(ISaga <,>)))
                .AsImplementedInterfaces()
                .AsSelf()
                .WithTransientLifetime()
                .AddClasses(t => t.AssignableTo(typeof(ISagaPersistence <,>)))
                .AsImplementedInterfaces()
                .WithTransientLifetime()
                ;
            });

            return(new ServiceRegistrar(services));
        }
예제 #3
0
        public Profile AddBindings(EndpointBindings bindings)
        {
            if (bindings == null || EndpointSettings.Count < 1)
            {
                return(this);
            }

            foreach (var binding in bindings.Endpoints)
            {
                var endpoint = EndpointSettings.SingleOrDefault(x => x.Name.Equals(binding.Name, StringComparison.OrdinalIgnoreCase));
                if (endpoint != null)
                {
                    if (String.IsNullOrEmpty(endpoint.ConnectionString))
                    {
                        endpoint.ConnectionString = binding.ConnectionString;
                    }
                }
            }
            return(this);
        }