public void TheyShouldBeResolvable()
        {
            var interceptorTypes = new[] {typeof (DummyInterceptor)};

            var builder = new ContainerBuilder();
            var typeProvider = Substitute.For<ITypeProvider>();
            typeProvider.InterceptorTypes.Returns(interceptorTypes);

            builder.RegisterNimbus(typeProvider);

            using (var container = builder.Build())
            using (var dependencyResolver = container.Resolve<IDependencyResolver>())
            using (var scope = dependencyResolver.CreateChildScope())
            {
                var interceptorSetting = new GlobalOutboundInterceptorTypesSetting
                                         {
                                             Value = interceptorTypes
                                         };
                var outboundInterceptorFactory = new OutboundInterceptorFactory(interceptorSetting,
                                                                                new PropertyInjector(Substitute.For<IClock>(),
                                                                                                     Substitute.For<IDispatchContextManager>(),
                                                                                                     Substitute.For<ILargeMessageBodyStore>()));

                var dummyNimbusMessage = new NimbusMessage("nullQueue");
                var interceptors = outboundInterceptorFactory.CreateInterceptors(scope, dummyNimbusMessage);

                interceptors.Count().ShouldBe(1);
            }
        }
示例#2
0
        public static void Init()
        {
            var serviceBusConnectionString = ConfigurationManager.ConnectionStrings["ServiceBus"].ConnectionString;
            var builder = new ContainerBuilder();
            var typeProvider = new AssemblyScanningTypeProvider(
                   Assembly.GetAssembly(typeof(ExampleEventHandler)),
                   Assembly.GetAssembly(typeof(ExampleCommand))
                   );

            var applicationName = Assembly.GetExecutingAssembly().ToNimbusName();
            var instanceName = Environment.MachineName;

            builder.RegisterNimbus(typeProvider);
            builder.RegisterType<NimbusLogger>().As<ILogger>();
            builder.Register(componetContext => new BusBuilder()
                .Configure()
                .WithConnectionString(serviceBusConnectionString)
                .WithNames(applicationName, instanceName)
                .WithTypesFrom(typeProvider)
                .WithDefaultTimeout(TimeSpan.FromSeconds(30))
                .WithAutofacDefaults(componetContext)
                .Build())
                .As<IBus>()
                .AutoActivate()
                .OnActivated(o => o.Instance.Start())
                .SingleInstance();

            _container = builder.Build();
        }
示例#3
0
        private static IContainer CreateContainer()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType<DeepThought>();

            builder.RegisterType<SerilogStaticLogger>()
                   .As<ILogger>()
                   .SingleInstance();

            //TODO: Set up your own connection string in app.config
            var connectionString = ConfigurationManager.AppSettings["AzureConnectionString"];

            var handlerTypesProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly());
            builder.RegisterNimbus(handlerTypesProvider);
            builder.Register(componentContext => new BusBuilder()
                                 .Configure()
                                 .WithConnectionString(connectionString)
                                 .WithNames("MyApp", Environment.MachineName)
                                 .WithTypesFrom(handlerTypesProvider)
                                 .WithAutofacDefaults(componentContext)
                                 .Build())
                   .As<IBus>()
                   .AutoActivate()
                   .OnActivated(c => c.Instance.Start())
                   .SingleInstance();

            var container = builder.Build();
            return container;
        }
示例#4
0
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            var connectionString = ConfigurationManager.AppSettings["AzureConnectionString"];

            // You'll want a logger. There's a ConsoleLogger and a NullLogger if you really don't care. You can roll your
            // own by implementing the ILogger interface if you want to hook it to an existing logging implementation.
            builder.RegisterType<ConsoleLogger>()
                   .AsImplementedInterfaces()
                   .SingleInstance();

            // This is how you tell Nimbus where to find all your message types and handlers.
            var pizzaOrderingMessagesAssembly = typeof (HowLongDoPizzasTakeRequest).Assembly;
            var pizzaMakerMessagesAssembly = typeof (PizzaIsReady).Assembly;
            var nimbusAssembly = typeof (Bus).Assembly; // for stock interceptors

            var handlerTypesProvider = new AssemblyScanningTypeProvider(ThisAssembly, pizzaOrderingMessagesAssembly, pizzaMakerMessagesAssembly, nimbusAssembly);

            builder.RegisterNimbus(handlerTypesProvider);
            builder.Register(componentContext => new BusBuilder()
                                 .Configure()
                                 .WithConnectionString(connectionString)
                                 .WithNames("MyApp", Environment.MachineName).WithTypesFrom(handlerTypesProvider)
                                 .WithAutofacDefaults(componentContext)
                                 .Build())
                   .As<IBus>()
                   .AutoActivate()
                   .OnActivated(c => c.Instance.Start())
                   .SingleInstance();
        }
示例#5
0
        private static void SetUpBus(ContainerBuilder builder)
        {
            //TODO: Set up your own connection string in app.config
            var connectionString = ConfigurationManager.AppSettings["AzureConnectionString"];

            // You'll want a logger. There's a ConsoleLogger and a NullLogger if you really don't care. You can roll your
            // own by implementing the ILogger interface if you want to hook it to an existing logging implementation.
            builder.RegisterType<ConsoleLogger>()
                   .AsImplementedInterfaces()
                   .SingleInstance();

            // This is how you tell Nimbus where to find all your message types and handlers.
            var typeProvider = new AssemblyScanningTypeProvider(Assembly.GetExecutingAssembly(), typeof (NewOrderRecieved).Assembly, typeof (HowLongDoPizzasTakeRequest).Assembly);

            builder.RegisterNimbus(typeProvider);
            builder.Register(componentContext => new BusBuilder()
                                 .Configure()
                                 .WithConnectionString(connectionString)
                                 .WithNames("WaitTime", Environment.MachineName)
                                 .WithTypesFrom(typeProvider)
                                 .WithAutofacDefaults(componentContext)
                                 .Build())
                   .As<IBus>()
                   .AutoActivate()
                   .OnActivated(c => c.Instance.Start())
                   .SingleInstance();
        }
示例#6
0
        public IBus Create()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType<ConsoleLogger>()
                   .AsImplementedInterfaces()
                   .SingleInstance();

            builder.RegisterNimbus(_typeProvider);
            builder.Register(componentContext => new BusBuilder()
                                 .Configure()
                                 .WithConnectionString(_connectionString)
                                 .WithNames("Maker", Environment.MachineName)
                                 .WithTypesFrom(_typeProvider)
                                 .WithAutofacDefaults(componentContext)
                                 .WithDebugOptions(
                                     dc =>
                                         dc.RemoveAllExistingNamespaceElementsOnStartup(
                                             "I understand this will delete EVERYTHING in my namespace. I promise to only use this for test suites."))
                                 .Build())
                   .As<IBus>()
                   .AutoActivate()
                   .OnActivated(c => c.Instance.Start())
                   .SingleInstance();

            var container = builder.Build();
            var bus = container.Resolve<IBus>();
            return bus;
        }
 private void BuildContainer(ITypeProvider typeProvider)
 {
     if (_container != null) throw new InvalidOperationException("This factory is only supposed to be used to construct one test subject.");
     var builder = new ContainerBuilder();
     builder.RegisterNimbus(typeProvider);
     _container = builder.Build();
 }
        public async Task NothingShouldGoBang()
        {
            var typeProvider = new AssemblyScanningTypeProvider(GetType().Assembly);

            var builder = new ContainerBuilder();
            builder.RegisterNimbus(typeProvider);

            using (builder.Build()) { }
        }
        public void NothingShouldGoBang()
        {
            var builder = new ContainerBuilder();
            var typeProvider = new AssemblyScanningTypeProvider();

            builder.RegisterType<ConsoleLogger>()
                   .As<ILogger>()
                   .SingleInstance();

            builder.RegisterNimbus(typeProvider);

            var largeMessageBodyTempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Guid.NewGuid().ToString());

            builder.Register(c => new FileSystemStorageBuilder().Configure()
                                                                .WithStorageDirectory(largeMessageBodyTempPath)
                                                                .WithLogger(c.Resolve<ILogger>())
                                                                .Build())
                   .As<ILargeMessageBodyStore>()
                   .SingleInstance();

            builder.Register(c => new BusBuilder().Configure()
                                                  .WithNames("IntegrationTestHarness", Environment.MachineName)
                                                  .WithConnectionString(
                                                      @"Endpoint=sb://shouldnotexist.example.com/;SharedAccessKeyName=IntegrationTestHarness;SharedAccessKey=borkborkbork=")
                                                  .WithLargeMessageStorage(sc => sc.WithLargeMessageBodyStore(c.Resolve<ILargeMessageBodyStore>())
                                                                                   .WithMaxSmallMessageSize(50*1024)
                                                                                   .WithMaxLargeMessageSize(1024*1024))
                                                  .WithTypesFrom(typeProvider)
                                                  .WithDefaultTimeout(TimeSpan.FromSeconds(10))
                                                  .WithLogger(c.Resolve<ILogger>())
                                                  .Build())
                   .As<IBus>()
                   .SingleInstance();

            using (var container = builder.Build())
            {
                container.Resolve<IBus>();
            }
        }
        /// <summary>
        /// Registers the configuration to the application
        /// </summary>
        public static IContainer Register()
        {
            var dbConnectionString = ConfigurationManager.ConnectionStrings["DbContext"].ConnectionString;
            var seviceBusConnectionString = ConfigurationManager.ConnectionStrings["ServiceBus"].ConnectionString;
            var builder = new ContainerBuilder();

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterRepositories(dbConnectionString);
            builder.RegisterExternalServices();
            builder.RegisterServices();
            builder.RegisterDummyServices();
            builder.RegisterNimbus(seviceBusConnectionString);

            var container = builder.Build();

            // Create the depenedency resolver.
            var resolver = new AutofacWebApiDependencyResolver(container);

            // Configure Web API with the dependency resolver.
            GlobalConfiguration.Configuration.DependencyResolver = resolver;

            return container;
        }
        public void TheyShouldBeResolvable()
        {
            var interceptorTypes = new[] {typeof (DummyInterceptor)};

            var builder = new ContainerBuilder();
            var typeProvider = Substitute.For<ITypeProvider>();
            typeProvider.InterceptorTypes.Returns(interceptorTypes);

            builder.RegisterNimbus(typeProvider);

            using (var container = builder.Build())
            using (var dependencyResolver = container.Resolve<IDependencyResolver>())
            using (var scope = dependencyResolver.CreateChildScope())
            {
                var interceptorSetting = new GlobalOutboundInterceptorTypesSetting
                                         {
                                             Value = interceptorTypes
                                         };
                var outboundInterceptorFactory = new OutboundInterceptorFactory(interceptorSetting);
                var interceptors = outboundInterceptorFactory.CreateInterceptors(scope);

                interceptors.Count().ShouldBe(1);
            }
        }
 public IDependencyResolver Create(ITypeProvider typeProvider)
 {
     var builder = new ContainerBuilder();
     builder.RegisterNimbus(typeProvider);
     return builder.Build().Resolve<IDependencyResolver>();
 }
示例#13
0
        private IContainer InitContainer()
        {
            var dbConnectionString = ConfigurationManager.ConnectionStrings["DbContext"].ConnectionString;
            var serviceBusConnectionString = ConfigurationManager.ConnectionStrings["ServiceBus"].ConnectionString;
            var builder = new ContainerBuilder();

            builder.RegisterRepositories(dbConnectionString);
            builder.RegisterServices();
            builder.RegisterNimbus(serviceBusConnectionString);

            return builder.Build();
        }