/// <summary> /// Setups up the service bus with the given IUnityContainer and registers the types found in the given type provider. /// </summary> public static BusBuilderConfiguration WithUnityDependencyResolver(this BusBuilderConfiguration configuration, ITypeProvider typeProvider, IUnityContainer unityContainer) { var dependencyResolver = new UnityDependencyResolver(unityContainer); unityContainer.RegisterInstance <IDependencyResolver>(dependencyResolver); unityContainer.RegisterInstance <ITypeProvider>(typeProvider); foreach (var resolvedType in typeProvider.AllResolvableTypes()) { unityContainer.RegisterType(resolvedType); } if (!unityContainer.IsRegistered <ILogger>()) { unityContainer.RegisterInstance <ILogger>(new NullLogger()); } return(configuration.WithLogger(unityContainer.Resolve <ILogger>()).WithDependencyResolver(dependencyResolver)); }
/// <summary> /// Setups up the service bus with the specified Unity Container and AssemblyScanningTypeProvider, then registers the types /// with the container. /// </summary> public static BusBuilderConfiguration WithUnityDependencyResolver(this BusBuilderConfiguration configuration, IUnityContainer unityContainer) { return(configuration.WithUnityDependencyResolver(new AssemblyScanningTypeProvider(Assembly.GetCallingAssembly()), unityContainer)); }
/// <summary> /// Setups up the service bus with a new Unity Container and registers the types found in the given type provider. /// </summary> public static BusBuilderConfiguration WithUnityDependencyResolver(this BusBuilderConfiguration configuration, ITypeProvider typeProvider) { return(configuration.WithUnityDependencyResolver(typeProvider, new UnityContainer())); }
internal static Bus Build(BusBuilderConfiguration configuration) { var logger = configuration.Logger; logger.Debug("Constructing bus..."); var container = new PoorMansIoC(); RegisterPropertiesFromConfigurationObject(container, configuration); RegisterPropertiesFromConfigurationObject(container, configuration.LargeMessageStorageConfiguration); RegisterPropertiesFromConfigurationObject(container, configuration.Debugging); var namespaceManagerRoundRobin = new RoundRobin<NamespaceManager>( container.Resolve<ServerConnectionCountSetting>(), () => { var namespaceManager = NamespaceManager.CreateFromConnectionString(container.Resolve<ConnectionStringSetting>()); namespaceManager.Settings.OperationTimeout = TimeSpan.FromSeconds(120); return namespaceManager; }, nsm => false, nsm => { }); container.Register<Func<NamespaceManager>>(c => namespaceManagerRoundRobin.GetNext); var messagingFactoryRoundRobin = new RoundRobin<Microsoft.ServiceBus.Messaging.MessagingFactory>( container.Resolve<ServerConnectionCountSetting>(), () => { var messagingFactory = Microsoft.ServiceBus.Messaging.MessagingFactory.CreateFromConnectionString(container.Resolve<ConnectionStringSetting>()); messagingFactory.PrefetchCount = container.Resolve<ConcurrentHandlerLimitSetting>(); return messagingFactory; }, mf => mf.IsBorked(), mf => { }); container.Register<Func<Microsoft.ServiceBus.Messaging.MessagingFactory>>(c => messagingFactoryRoundRobin.GetNext); if (configuration.Debugging.RemoveAllExistingNamespaceElements) { var namespaceCleanser = container.Resolve<NamespaceCleanser>(); namespaceCleanser.RemoveAllExistingNamespaceElements().Wait(); } logger.Debug("Creating message pumps..."); container.Register(new IHeartbeatListener[] { container.Resolve<EventSenderListener>() }); var messagePumps = new MessagePumpsManager( container.Resolve<ResponseMessagePumpFactory>().Create(), container.Resolve<RequestMessagePumpsFactory>().CreateAll(), container.Resolve<CommandMessagePumpsFactory>().CreateAll(), container.Resolve<MulticastRequestMessagePumpsFactory>().CreateAll(), container.Resolve<MulticastEventMessagePumpsFactory>().CreateAll(), container.Resolve<CompetingEventMessagePumpsFactory>().CreateAll(), container.Resolve<ITaskFactory>()); logger.Debug("Message pumps are all created."); var bus = new Bus(container.Resolve<ILogger>(), container.Resolve<ICommandSender>(), container.Resolve<IRequestSender>(), container.Resolve<IMulticastRequestSender>(), container.Resolve<IEventSender>(), messagePumps, container.Resolve<DeadLetterQueues>(), container.Resolve<ITaskFactory>(), container.Resolve<IHeartbeat>()); bus.Starting += delegate { if (configuration.WarmUpAzureQueueManagerDuringStartup) { container.Resolve<AzureQueueManager>().WarmUp(); } container.Resolve<PropertyInjector>().Bus = bus; }; bus.Disposing += delegate { container.Dispose(); }; logger.Info("Bus built. Job done!"); return bus; }
/// <summary> /// To provide custom serialization using the <see cref="Newtonsoft.Json.JsonSerializer" />. /// </summary> /// <param name="configuration">The bus configuration to apply the serializer to.</param> /// <returns>Bus configuration.</returns> public static BusBuilderConfiguration WithJsonSerializer(this BusBuilderConfiguration configuration) { return(configuration.WithSerializer(new JsonSerializer())); }
/// <summary> /// To provide custom serialization using the <see cref="Newtonsoft.Json.JsonSerializer" />. /// </summary> /// <param name="configuration">The bus configuration to apply the serializer to.</param> /// <param name="settings">To configure serialization settings.</param> /// <returns>Bus configuration.</returns> public static BusBuilderConfiguration WithJsonSerializer(this BusBuilderConfiguration configuration, JsonSerializerSettings settings) { return(configuration.WithSerializer(new JsonSerializer(settings))); }
/// <summary> /// Log to the provided Log4net <see cref="log4net.ILog" />. /// </summary> /// <param name="configuration">The bus configuration to apply the logger to.</param> /// <param name="logger">The logger.</param> /// <returns>Bus configuration.</returns> public static BusBuilderConfiguration WithLog4netLogger(this BusBuilderConfiguration configuration, ILog logger) { return(configuration .WithLogger(new Log4NetLogger(logger))); }
/// <summary> /// Log to the Serilog <see cref="Log" /> class. /// </summary> /// <param name="configuration">The bus configuration to apply the logger to.</param> /// <returns>Bus configuration.</returns> public static BusBuilderConfiguration WithSerilogLogger(this BusBuilderConfiguration configuration) { return(configuration .WithLogger(new SerilogStaticLogger())); }