当前位置: 首页>>代码示例>>C#>>正文


C# BusConfiguration.UseContainer方法代码示例

本文整理汇总了C#中BusConfiguration.UseContainer方法的典型用法代码示例。如果您正苦于以下问题:C# BusConfiguration.UseContainer方法的具体用法?C# BusConfiguration.UseContainer怎么用?C# BusConfiguration.UseContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BusConfiguration的用法示例。


在下文中一共展示了BusConfiguration.UseContainer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Customize

        public void Customize(BusConfiguration configuration)
        {
            // NServiceBus provides the following durable storage options
            // To use RavenDB, install-package NServiceBus.RavenDB and then use configuration.UsePersistence<RavenDBPersistence>();
            // To use SQLServer, install-package NServiceBus.NHibernate and then use configuration.UsePersistence<NHibernatePersistence>();

            // If you don't need a durable storage you can also use, configuration.UsePersistence<InMemoryPersistence>();
            // more details on persistence can be found here: http://docs.particular.net/nservicebus/persistence-in-nservicebus

            //Also note that you can mix and match storages to fit you specific needs.
            //http://docs.particular.net/nservicebus/persistence-order

            string mongoDbConnectionString = ConfigurationManager.AppSettings["MongoDB"];

            configuration.UsePersistence<InMemoryPersistence>();
            configuration.UseSerialization<JsonSerializer>();

            ContainerBuilder builder = new ContainerBuilder();
            builder.RegisterType<RosterDocumentContext>().SingleInstance();
            builder.RegisterType<MongoDBDocumentProvider>()
                .As<IDocumentProvider>()
                .WithParameter("connectionString", mongoDbConnectionString);
            IContainer container = builder.Build();
            configuration.UseContainer<AutofacBuilder>(x => x.ExistingLifetimeScope(container));
        }
开发者ID:belsberry,项目名称:roster-distributed-application,代码行数:25,代码来源:EndpointConfig.cs

示例2: Application_Start

    protected void Application_Start()
    {
        #region ApplicationStart

        ContainerBuilder builder = new ContainerBuilder();

        // Register your MVC controllers.
        builder.RegisterControllers(typeof(MvcApplication).Assembly);

        // Set the dependency resolver to be Autofac.
        IContainer container = builder.Build();

        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.MvcInjection.WebApplication");
        // ExistingLifetimeScope() ensures that IBus is added to the container as well,
        // allowing you to resolve IBus from your own components.
        busConfiguration.UseContainer<AutofacBuilder>(c => c.ExistingLifetimeScope(container));
        busConfiguration.UseSerialization<JsonSerializer>();
        busConfiguration.UsePersistence<InMemoryPersistence>();
        busConfiguration.EnableInstallers();

        bus = Bus.CreateSendOnly(busConfiguration);

        DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

        AreaRegistration.RegisterAllAreas();
        RegisterRoutes(RouteTable.Routes);

        #endregion
    }
开发者ID:cdnico,项目名称:docs.particular.net,代码行数:30,代码来源:Global.asax.cs

示例3: ConfigureBus

        public static void ConfigureBus(IWindsorContainer container)
        {
            // Use NLog for logging
            NServiceBus.Logging.LogManager.Use<NLogFactory>();

            var configuration = new BusConfiguration();
            // Only scan known Messages assemblies rather than all assemblies in 'bin' - faster startup time.
            var messages = AppDomain.CurrentDomain.GetAssemblies()
                .Where(a => a.GetName().Name.EndsWith(".Messages"));
            configuration.AssembliesToScan(messages);
            // Use NServiceBus Unobtrusive Mode
            configuration.Conventions()
                .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.EndsWith("Commands"))
                .DefiningEventsAs(t => t.Namespace != null && t.Namespace.EndsWith("Events"))
                .DefiningMessagesAs(t => t.Namespace != null && t.Namespace == "Messages")
                .DefiningDataBusPropertiesAs(p => p.Name.EndsWith("DataBus"))
                .DefiningExpressMessagesAs(t => t.Name.EndsWith("Express"))
                .DefiningTimeToBeReceivedAs(t => t.Name.EndsWith("Expires")
                    ? TimeSpan.FromSeconds(30) : TimeSpan.MaxValue);
            // Use existing Castle Windsor container
            configuration.UseContainer<WindsorBuilder>(c => c.ExistingContainer(container));
            // Use JSON for serialisation
            configuration.UseSerialization<JsonSerializer>();
            // Use MSMQ for transport
            configuration.UseTransport<MsmqTransport>();
            // Use InMemory persistence only
            configuration.UsePersistence<InMemoryPersistence>();
            configuration.EnableInstallers();

            // Start the bus
            var bus = Bus.Create(configuration);
            bus.Start();
        }
开发者ID:laazyj,项目名称:MessageBusArchitectureExample,代码行数:33,代码来源:BusConfig.cs

示例4: Application_Start

    protected void Application_Start()
    {
        #region ApplicationStart

        ContainerBuilder builder = new ContainerBuilder();

        // Register MVC controllers.
        builder.RegisterControllers(typeof(MvcApplication).Assembly);

        // Set the dependency resolver to be Autofac.
        IContainer container = builder.Build();

        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.MvcInjection.WebApplication");
        // instruct NServiceBus to use a custom AutoFac configuration
        busConfiguration.UseContainer<AutofacBuilder>(c => c.ExistingLifetimeScope(container));
        busConfiguration.UseSerialization<JsonSerializer>();
        busConfiguration.UsePersistence<InMemoryPersistence>();
        busConfiguration.EnableInstallers();
        busConfiguration.SendFailedMessagesTo("error");

        endpoint = Endpoint.Start(busConfiguration).GetAwaiter().GetResult();

        ContainerBuilder updater = new ContainerBuilder();
        updater.RegisterInstance(endpoint);
        updater.Update(container);

        DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

        AreaRegistration.RegisterAllAreas();
        RegisterRoutes(RouteTable.Routes);

        #endregion
    }
开发者ID:vanwyngardenk,项目名称:docs.particular.net,代码行数:34,代码来源:Global.asax.cs

示例5: AsyncMain

    static async Task AsyncMain()
    {
        #region ContainerConfiguration
        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.Unity");

        UnityContainer container = new UnityContainer();
        container.RegisterInstance(new MyService());
        busConfiguration.UseContainer<UnityBuilder>(c => c.UseExistingContainer(container));
        #endregion
        busConfiguration.UseSerialization<JsonSerializer>();
        busConfiguration.UsePersistence<InMemoryPersistence>();
        busConfiguration.EnableInstallers();
        busConfiguration.SendFailedMessagesTo("error");

        IEndpointInstance endpoint = await Endpoint.Start(busConfiguration);
        try
        {
            IBusSession busSession = endpoint.CreateBusSession();
            await busSession.SendLocal(new MyMessage());
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
        finally
        {
            await endpoint.Stop();
        }
    }
开发者ID:cdnico,项目名称:docs.particular.net,代码行数:28,代码来源:Program.cs

示例6: Main

        static void Main()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType<Program>();

            var container = builder.Build();

            var configuration = new BusConfiguration();

            configuration.UseContainer<AutofacBuilder>(c => c.ExistingLifetimeScope(container));

            configuration.UseTransport<AzureStorageQueueTransport>()
                .ConnectionString("UseDevelopmentStorage=true");
            configuration.UsePersistence<AzureStoragePersistence>();
            configuration.UseSerialization<JsonSerializer>();

            configuration.DisableFeature<Sagas>();
            configuration.DisableFeature<TimeoutManager>();

            configuration.Conventions().DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("NServiceBusDemo.Messages.Commands"));
            configuration.Conventions().DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("NServiceBusDemo.Messages.Events"));
            configuration.Conventions().DefiningMessagesAs(t => t.Namespace != null && t.Namespace.StartsWith("NServiceBusDemo.Messages.Responses"));

            Bus.Create(configuration).Start();

            using (var scope = container.BeginLifetimeScope())
            {
                scope.Resolve<Program>().Run();
            }
        }
开发者ID:Rommel-Villa,项目名称:NSB_Spike,代码行数:31,代码来源:Program.cs

示例7: AsyncMain

    static async Task AsyncMain()
    {
        #region ContainerConfiguration

        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.Autofac");

        ContainerBuilder builder = new ContainerBuilder();
        builder.RegisterInstance(new MyService());
        IContainer container = builder.Build();
        busConfiguration.UseContainer<AutofacBuilder>(c => c.ExistingLifetimeScope(container));

        #endregion

        busConfiguration.UseSerialization<JsonSerializer>();
        busConfiguration.UsePersistence<InMemoryPersistence>();
        busConfiguration.EnableInstallers();
        busConfiguration.SendFailedMessagesTo("error");

        using (IBus bus = await Bus.Create(busConfiguration).StartAsync())
        {
            await bus.SendLocalAsync(new MyMessage());
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
    }
开发者ID:RichieYang,项目名称:docs.particular.net,代码行数:26,代码来源:Program.cs

示例8: Application_Start

        protected void Application_Start()
        {
            ContainerBuilder builder = new ContainerBuilder();

            // Register your MVC controllers.
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterType<MyPathMessageCreator>().As<IMyPathMessageCreator>().InstancePerRequest();

            // Set the dependency resolver to be Autofac.
            IContainer container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            BusConfiguration busConfiguration = new BusConfiguration();
            busConfiguration.EndpointName("MyPathX.Web");
            busConfiguration.UseSerialization<JsonSerializer>();
            busConfiguration.UseContainer<AutofacBuilder>(c => c.ExistingLifetimeScope(container));
            busConfiguration.UsePersistence<InMemoryPersistence>();
            busConfiguration.EnableInstallers();

            var startableBus = Bus.Create(busConfiguration);
            bus = startableBus.Start();

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
开发者ID:avbutnaru,项目名称:mypathx,代码行数:28,代码来源:Global.asax.cs

示例9: InitServiceBus

        private void InitServiceBus(BusConfiguration config, IContainer container)
        {
            // Configure Logging
            NServiceBus.Logging.LogManager.Use<Log4NetFactory>();

            // Configure container
            config.UseContainer<StructureMapBuilder>(c => c.ExistingContainer(container));

            // Xml serialization makes for easy to read messages.
            config.UseSerialization<JsonSerializer>();

            //Define conventions
            ConventionsBuilder conventions = config.Conventions();
            conventions.DefiningCommandsAs(MessageTypeConventions.EndsWith("Command"));
            conventions.DefiningEventsAs(MessageTypeConventions.EndsWith("Event"));
            conventions.DefiningMessagesAs(MessageTypeConventions.EndsWith("Message"));

            // Keep it simple by default
            config.DisableFeature<SecondLevelRetries>();
            config.DisableFeature<AutoSubscribe>();
            config.DisableFeature<TimeoutManager>();
            config.DisableFeature<DataBus>();

            // Configure for MSMQ
            config.UseTransport<MsmqTransport>();
            config.Transactions().Enable();
            config.PurgeOnStartup(false);

            // Configure Saga Persistence
            config.UsePersistence<InMemoryPersistence>();
        }
开发者ID:techvenky,项目名称:microservice-template,代码行数:31,代码来源:EndpointConfig.cs

示例10: AsyncMain

    static async Task AsyncMain()
    {
        #region ContainerConfiguration
        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.Spring");

        GenericApplicationContext applicationContext = new GenericApplicationContext();
        applicationContext.ObjectFactory.RegisterSingleton("MyService", new MyService());
        busConfiguration.UseContainer<SpringBuilder>(c => c.ExistingApplicationContext(applicationContext));
        #endregion
        busConfiguration.UseSerialization<JsonSerializer>();
        busConfiguration.UsePersistence<InMemoryPersistence>();

        busConfiguration.SendFailedMessagesTo("error");

        IEndpointInstance endpoint = await Endpoint.Start(busConfiguration);
        try
        {
            await endpoint.SendLocal(new MyMessage());
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
        finally
        {
            await endpoint.Stop();
        }
    }
开发者ID:vanwyngardenk,项目名称:docs.particular.net,代码行数:27,代码来源:Program.cs

示例11: OnStart

        protected override void OnStart(string[] args)
        {
            try
            {
                container = new Container(x => x.AddRegistry<DependencyRegistry>());
                var myDocumentStore = new DocumentStore { ConnectionStringName = "EpiFlowDB" };

                var busConfiguration = new BusConfiguration();
                busConfiguration.EndpointName("EpiFlow.Messages");
                busConfiguration.UseContainer<StructureMapBuilder>(c => c.ExistingContainer(container));
                busConfiguration.UseSerialization<JsonSerializer>();
                busConfiguration.UsePersistence<RavenDBPersistence>()
                    .UseDocumentStoreForSubscriptions(myDocumentStore)
                    .UseDocumentStoreForSagas(myDocumentStore)
                    .UseDocumentStoreForTimeouts(myDocumentStore);
                busConfiguration.UseTransport<RabbitMQTransport>();
                busConfiguration.DefineCriticalErrorAction(OnCriticalError);
                busConfiguration.Transactions().DisableDistributedTransactions();

                if (Environment.UserInteractive && Debugger.IsAttached)
                {
                    busConfiguration.EnableInstallers();
                }
                var startableBus = Bus.Create(busConfiguration);
                bus = startableBus.Start();
            }
            catch (Exception exception)
            {
                OnCriticalError("Failed to start the bus.", exception);
            }
        }
开发者ID:wettsten,项目名称:EpiFlow,代码行数:31,代码来源:ProgramService.cs

示例12: Application_Start

    protected void Application_Start()
    {
        #region ApplicationStart

        ContainerBuilder builder = new ContainerBuilder();

        // Register your MVC controllers.
        builder.RegisterControllers(typeof(MvcApplication).Assembly);

        // Set the dependency resolver to be Autofac.
        IContainer container = builder.Build();

        DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.Mvc.WebApplication");
        busConfiguration.UseSerialization<JsonSerializer>();
        busConfiguration.UseContainer<AutofacBuilder>(c => c.ExistingLifetimeScope(container));
        busConfiguration.UsePersistence<InMemoryPersistence>();
        busConfiguration.EnableInstallers();

        IStartableBus startableBus = Bus.Create(busConfiguration);
        bus = startableBus.Start();

        AreaRegistration.RegisterAllAreas();
        RegisterRoutes(RouteTable.Routes);

        #endregion
    }
开发者ID:vanwyngardenk,项目名称:docs.particular.net,代码行数:29,代码来源:Global.asax.cs

示例13: Main

    static void Main()
    {
        #region autofac

        ContainerBuilder builder = new ContainerBuilder();
        builder.RegisterGeneric(typeof(Repository<>))
              .As(typeof(IRepository<>));
        builder.RegisterType<EventStore>().As<IEventStore>();
        builder.RegisterType(typeof(ICommand));
        builder.RegisterType(typeof(IMessage));
        Container = builder.Build();

        #endregion autofac

        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.StepByStep.Server");
        busConfiguration.UseSerialization<JsonSerializer>();
        busConfiguration.EnableInstallers();
        busConfiguration.UsePersistence<InMemoryPersistence>();
        busConfiguration.UseContainer<AutofacBuilder>(c => c.ExistingLifetimeScope(Container));
        using (IBus bus = Bus.Create(busConfiguration).Start())
        {
            Console.WriteLine("Press any key to exit server");
            Console.ReadKey();
        }

        //using (var scope = Container.BeginLifetimeScope())
        //{
        //    var repsoitory = scope.Resolve<IRepository<MedicalApprovalProcedure>>();
        //    repsoitory.GetById(Guid.NewGuid());

        //}
    }
开发者ID:asajjad,项目名称:ManteqDeveloperTest,代码行数:33,代码来源:Program.cs

示例14: Main

    static void Main()
    {
        Console.Title = "Samples.Castle";
        #region ContainerConfiguration
        var busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.Castle");

        var container = new WindsorContainer();
        container.Register(Component.For<MyService>().Instance(new MyService()));

        busConfiguration.UseContainer<WindsorBuilder>(c => c.ExistingContainer(container));
        #endregion

        busConfiguration.UseSerialization<JsonSerializer>();
        busConfiguration.UsePersistence<InMemoryPersistence>();
        busConfiguration.EnableInstallers();

        using (var bus = Bus.Create(busConfiguration).Start())
        {
            var myMessage = new MyMessage();
            bus.SendLocal(myMessage);
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
    }
开发者ID:chriscatilo,项目名称:docs.particular.net,代码行数:25,代码来源:Program.cs

示例15: Customize

        public void Customize(BusConfiguration configuration)
        {
            XmlConfigurator.Configure();
            configuration.UseContainer<NinjectBuilder>(k => k.ExistingKernel(CreateKernel()));
            configuration.RegisterComponents(x => x.ConfigureComponent<IRepository>(
                builder =>
                {
                    return new Repository(() =>
                    {
                        var nh = builder.Build<NHibernateStorageContext>();
                        var e = new OrderContext((DbConnection)nh.Connection);
                        return e;
                    });
                },
                DependencyLifecycle.InstancePerUnitOfWork));
            configuration.RegisterComponents(components => components.ConfigureComponent<UnitOfWork>(DependencyLifecycle.InstancePerUnitOfWork));

            configuration.UsePersistence<NHibernatePersistence>();
            configuration.UseTransport<MsmqTransport>();
            configuration.UseDataBus<FileShareDataBus>().BasePath(Constants.NServiceBus_DataBusBasePath);
            configuration.RijndaelEncryptionService();
            configuration.Transactions();
            configuration.EnableOutbox();
            configuration.Conventions().OrderConventions();
            //
        }
开发者ID:eraj2587,项目名称:NserviceBusDemo,代码行数:26,代码来源:EndpointConfig.cs


注:本文中的BusConfiguration.UseContainer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。