Пример #1
0
        public void CapturesServiceExceptionDetails()
        {
            var methodInfo = GetType().GetMethod(nameof(InjectedMethod), BindingFlags.NonPublic | BindingFlags.Static);

            Assert.NotNull(methodInfo);

            var services = new ServiceCollection()
                           .AddSingleton <CrasherService>()
                           .BuildServiceProvider();

            var applicationBuilder = new ApplicationBuilder(services);

            var builder = new ConfigureBuilder(methodInfo);
            Action <IApplicationBuilder> action = builder.Build(instance: null);
            var ex = Assert.Throws <Exception>(() => action.Invoke(applicationBuilder));

            Assert.NotNull(ex);
            Assert.Equal($"Could not resolve a service of type '{typeof(CrasherService).FullName}' for the parameter"
                         + $" 'service' of method '{methodInfo.Name}' on type '{methodInfo.DeclaringType.FullName}'.", ex.Message);

            // the inner exception contains the root cause
            Assert.NotNull(ex.InnerException);
            Assert.Equal("Service instantiation failed", ex.InnerException.Message);
            Assert.Contains(nameof(CrasherService), ex.InnerException.StackTrace);
        }
        public static IServiceCollection AddServiceBusRetryPolicy(this IServiceCollection services,
                                                                  ConfigureBuilder builder)
        {
            services.AddSingleton <IServiceBusRetryHandler>(_ => ServiceBusRetryHandler.Instance);

            services.AddSingleton <IServiceBusPolicy, ServiceBusPolicy>();
            services.AddTransient(_ => builder);
            return(services);
        }
Пример #3
0
 public ServiceBusPolicy(IServiceBusRetryHandler serviceBusRetryHandler,
                         ConfigureBuilder configureBuilder) => (_serviceBusRetryHandler, _configureBuilder) = (serviceBusRetryHandler, configureBuilder);