Example #1
0
 public NatsModuleBuilder(IServiceCollection services, NatsSettings natsSettings)
     : base(services)
 {
     _natsSettings = natsSettings;
 }
Example #2
0
        public static IServiceCollection AddNatsServices(this IServiceCollection services, NatsSettings natsSenderOptions)
        {
            return(services.AddTransient <INatsSerializer, NatsSerializer>()
                   .AddSingleton <INatsConnectionFactory>(cf =>
            {
                var serializer = (INatsSerializer)cf.GetService(typeof(INatsSerializer));

                var natsOptions = ConnectionFactory.GetDefaultOptions();
                natsOptions.Url = natsSenderOptions.Url;
                natsOptions.Timeout = 60000;
                natsOptions.User = natsSenderOptions.User;
                natsOptions.Password = natsSenderOptions.Password;

                return new NatsConnectionFactory(serializer, natsOptions);
            }));
        }