static void Main(string[] args) { // Using StructureMap for IoC. You can use Ninject, AutoFac, Windsor, or whatever // supports the methods you need to override in SeekUHostConfiguration<T> var host = new SeekUHostConfiguration<SeekUDemoDependencyResolver>(); // Configure the host to use SQL to store events and snapshots. You don't have to use // the configuration action - both providers will default to a connection string // named "SeekU." This simply shows how you can configure each provider at runtime. host // Sample of using configuration actions to set connectionstrings .ForEventStore().Use<SqlEventStore>(store => { store.ConnectionStringName = "DemoConnectionString"; }) // This could be a different connection if necessary .ForSnapshotStore().Use<SqlSnapshotStore>(store => { store.ConnectionStringName = "DemoConnectionString"; }); // Using the default conenction string would look like this (less verbose): //config.ForEventStore().Use<SqlEventStore>().ForSnapshotStore().Use<SqlSnapshotStore>(); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
static void Main(string[] args) { // Using StructureMap for IoC. You can use Ninject, AutoFac, Windsor, or whatever // supports the methods you need to override in SeekUHostConfiguration<T> var host = new SeekUHostConfiguration<SeekUDemoDependencyResolver>(); // Configure file-based event storeage host.ForEventStore().Use<JsonFileEventStore>() // Example of using an optional configuration action. In this cas it sets the snapshot store's file name .ForSnapshotStore().Use<JsonFileSnapshotStore>(store => { store.FileName = "snapshot-instance.json"; }); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
static BankAccountHandler() { // Use the default in memory providers, so no configuration is necessary. Host = new SeekUHostConfiguration <NsbStructureMapResolver>(); //Host = new Host(config); }
static void Main(string[] args) { // Using StructureMap for IoC. You can use Ninject, AutoFac, Windsor, or whatever // supports the methods you need to override in SeekUHostConfiguration<T> var host = new SeekUHostConfiguration <SeekUDemoDependencyResolver>(); // Configure file-based event storeage host.ForEventStore().Use <JsonFileEventStore>() // Example of using an optional configuration action. In this cas it sets the snapshot store's file name .ForSnapshotStore().Use <JsonFileSnapshotStore>(store => { store.FileName = "snapshot-instance.json"; }); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
static void Main(string[] args) { // Use MongoDB for event and snapshot storage var host = new SeekUHostConfiguration <SeekUDemoDependencyResolver>(); host.ForEventStore().Use <MongoEventStore>() .ForSnapshotStore().Use <MongoSnapshotStore>(); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
static void Main(string[] args) { // Using StructureMap for IoC. You can use Ninject, AutoFac, Windsor, or whatever // supports the methods you need to override in SeekUHostConfiguration<T> var host = new SeekUHostConfiguration <SeekUDemoDependencyResolver>(); // Configure the host to use SQL to store events and snapshots. You don't have to use // the configuration action - both providers will default to a connection string // named "SeekU." This simply shows how you can configure each provider at runtime. host // Sample of using configuration actions to set connectionstrings .ForEventStore().Use <SqlEventStore>(store => { store.ConnectionStringName = "DemoConnectionString"; }) // This could be a different connection if necessary .ForSnapshotStore().Use <SqlSnapshotStore>(store => { store.ConnectionStringName = "DemoConnectionString"; }); // Using the default conenction string would look like this (less verbose): //config.ForEventStore().Use<SqlEventStore>().ForSnapshotStore().Use<SqlSnapshotStore>(); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
private void SendSeekU() { // Use a custom configuration with our own ICommandBus implementation var host = new SeekUHostConfiguration <NsbStructureMapResolver>(); // Configure commands to be published via NServiceBus instead of the // in-memory bus. host.ForCommandBus().Use <NServiceCommandBus>(); // The NServiceCommandBus requires IBus as a constructor parameter. // This tells the resolver what to use for that dependency. host.For <IBus>().Use(Bus); var seekUBus = host.GetCommandBus(); var id = Guid.NewGuid(); Console.WriteLine("Sending create account command"); seekUBus.Send(new CreateNewAccountCommand(id, 950)); Console.WriteLine("Sending debit account command"); seekUBus.Send(new DebitAccountCommand(id, 50)); Console.WriteLine("Sending credit account command"); seekUBus.Send(new CreditAccountCommand(id, 120)); Console.WriteLine("Sending debit account command"); seekUBus.Send(new DebitAccountCommand(id, 350)); }
static void Main(string[] args) { // Using StructureMap for IoC. You can use Ninject, AutoFac, Windsor, or whatever // supports the methods you need to override in SeekUHostConfiguration<T> var config = new SeekUHostConfiguration <SeekUDemoDependencyResolver>(); // Normally you'd configure providers here. This "in memory" sample // uses the default providers, so no configuration is necessary. var bus = config.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account var newAccountCommand = new CreateNewAccountCommand(id, 950); // Simple validation example. var validation = bus.Validate(newAccountCommand); Console.WriteLine("CreateNewAccountCommand is valid? {0}", validation.Success); bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
static void Main(string[] args) { // Using StructureMap for IoC. You can use Ninject, AutoFac, Windsor, or whatever // supports the methods you need to override in SeekUHostConfiguration<T> var config = new SeekUHostConfiguration<SeekUDemoDependencyResolver>(); // Normally you'd configure providers here. This "in memory" sample // uses the default providers, so no configuration is necessary. var bus = config.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account var newAccountCommand = new CreateNewAccountCommand(id, 950); // Simple validation example. var validation = bus.Validate(newAccountCommand); Console.WriteLine("CreateNewAccountCommand is valid? {0}", validation.Success); bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
static void UseStructureMap() { Console.WriteLine("\r\n================\r\n"); Console.WriteLine("Press a key to run with StructureMap"); Console.ReadKey(); // Configure using StructureMap var structureMapConfig = new SeekUHostConfiguration<StructureMapResolver>(); structureMapConfig.ForSnapshotStore().Use<InMemorySnapshotStore>(store => ArbitraryConfigurationStep("StructureMap", store)); structureMapConfig.For<IExample>().Use<Example>(); IssueBankAccountCommands(structureMapConfig); }
static void UseNinject() { Console.WriteLine("Press a key to run with Ninject"); Console.ReadKey(); // Configure using Ninject var ninjectConfig = new SeekUHostConfiguration<NinjectResolver>(); ninjectConfig.ForSnapshotStore().Use<InMemorySnapshotStore>(store => ArbitraryConfigurationStep("Ninject", store)); ninjectConfig.For<IExample>().Use<Example>(); IssueBankAccountCommands(ninjectConfig); }
static void UseNinject() { Console.WriteLine("Press a key to run with Ninject"); Console.ReadKey(); // Configure using Ninject var ninjectConfig = new SeekUHostConfiguration <NinjectResolver>(); ninjectConfig.ForSnapshotStore().Use <InMemorySnapshotStore>(store => ArbitraryConfigurationStep("Ninject", store)); ninjectConfig.For <IExample>().Use <Example>(); IssueBankAccountCommands(ninjectConfig); }
static void UseWindsor() { Console.WriteLine("\r\n================\r\n"); Console.WriteLine("Press a key to run with Castle Windsor"); Console.ReadKey(); // Configure using Windsor var ninjectConfig = new SeekUHostConfiguration<WindsorResolver>(); ninjectConfig.ForSnapshotStore().Use<InMemorySnapshotStore>(store => ArbitraryConfigurationStep("Windsor", store)); ninjectConfig.For<IExample>().Use<Example>(); IssueBankAccountCommands(ninjectConfig); }
static void UseStructureMap() { Console.WriteLine("\r\n================\r\n"); Console.WriteLine("Press a key to run with StructureMap"); Console.ReadKey(); // Configure using StructureMap var structureMapConfig = new SeekUHostConfiguration <StructureMapResolver>(); structureMapConfig.ForSnapshotStore().Use <InMemorySnapshotStore>(store => ArbitraryConfigurationStep("StructureMap", store)); structureMapConfig.For <IExample>().Use <Example>(); IssueBankAccountCommands(structureMapConfig); }
static void UseWindsor() { Console.WriteLine("\r\n================\r\n"); Console.WriteLine("Press a key to run with Castle Windsor"); Console.ReadKey(); // Configure using Windsor var ninjectConfig = new SeekUHostConfiguration <WindsorResolver>(); ninjectConfig.ForSnapshotStore().Use <InMemorySnapshotStore>(store => ArbitraryConfigurationStep("Windsor", store)); ninjectConfig.For <IExample>().Use <Example>(); IssueBankAccountCommands(ninjectConfig); }
static void Main(string[] args) { // Use MongoDB for event and snapshot storage var host = new SeekUHostConfiguration<SeekUDemoDependencyResolver>(); // Update with your connection string const string connectionString = "DefaultEndpointsProtocol=https;AccountName=[Your account name];AccountKey[Your account key]"; host .ForEventStore().Use<AzureTableEventStore>(store => { store.TableConnectionString = connectionString; }) .ForSnapshotStore().Use<AzureBlobSnapshotStore>(store => { store.BlobConnectionString = connectionString; }); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 95)); Console.WriteLine("Azure event created"); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 5)); Console.WriteLine("Azure event created"); bus.Send(new CreditAccountCommand(id, 12)); Console.WriteLine("Azure event created"); Console.WriteLine("Azure snapshot created"); bus.Send(new DebitAccountCommand(id, 35)); Console.WriteLine("Azure event created"); Console.Read(); }
static void Main(string[] args) { // Use MongoDB for event and snapshot storage var host = new SeekUHostConfiguration <SeekUDemoDependencyResolver>(); // Update with your connection string const string connectionString = "DefaultEndpointsProtocol=https;AccountName=[Your account name];AccountKey[Your account key]"; host .ForEventStore().Use <AzureTableEventStore>(store => { store.TableConnectionString = connectionString; }) .ForSnapshotStore().Use <AzureBlobSnapshotStore>(store => { store.BlobConnectionString = connectionString; }); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 95)); Console.WriteLine("Azure event created"); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 5)); Console.WriteLine("Azure event created"); bus.Send(new CreditAccountCommand(id, 12)); Console.WriteLine("Azure event created"); Console.WriteLine("Azure snapshot created"); bus.Send(new DebitAccountCommand(id, 35)); Console.WriteLine("Azure event created"); Console.Read(); }
public override bool OnStart() { _host = new SeekUHostConfiguration <SeekUDemoDependencyResolver>(); // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; // Create the queue if it does not exist already var connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString"); var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); if (!namespaceManager.QueueExists(QueueName)) { namespaceManager.CreateQueue(QueueName); } // Initialize the connection to Service Bus Queue _client = QueueClient.CreateFromConnectionString(connectionString, QueueName); return(base.OnStart()); }
static void Main(string[] args) { // Use MongoDB for event and snapshot storage var host = new SeekUHostConfiguration<SeekUDemoDependencyResolver>(); host.ForEventStore().Use<MongoEventStore>() .ForSnapshotStore().Use<MongoSnapshotStore>(); var bus = host.GetCommandBus(); // I'm not a proponent of Guids for primary keys. This method returns // a sequential Guid to make database sorting behave like integers. // http://www.informit.com/articles/article.asp?p=25862 var id = SequentialGuid.NewId(); // Create the account bus.Send(new CreateNewAccountCommand(id, 950)); // Use the account to create a history of events including a snapshot bus.Send(new DebitAccountCommand(id, 50)); bus.Send(new CreditAccountCommand(id, 120)); bus.Send(new DebitAccountCommand(id, 350)); Console.Read(); }
private void SendSeekU() { // Use a custom configuration with our own ICommandBus implementation var host = new SeekUHostConfiguration<NsbStructureMapResolver>(); // Configure commands to be published via NServiceBus instead of the // in-memory bus. host.ForCommandBus().Use<NServiceCommandBus>(); // The NServiceCommandBus requires IBus as a constructor parameter. // This tells the resolver what to use for that dependency. host.For<IBus>().Use(Bus); var seekUBus = host.GetCommandBus(); var id = Guid.NewGuid(); Console.WriteLine("Sending create account command"); seekUBus.Send(new CreateNewAccountCommand(id, 950)); Console.WriteLine("Sending debit account command"); seekUBus.Send(new DebitAccountCommand(id, 50)); Console.WriteLine("Sending credit account command"); seekUBus.Send(new CreditAccountCommand(id, 120)); Console.WriteLine("Sending debit account command"); seekUBus.Send(new DebitAccountCommand(id, 350)); }
public override bool OnStart() { _host = new SeekUHostConfiguration<SeekUDemoDependencyResolver>(); // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; // Create the queue if it does not exist already var connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString"); var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); if (!namespaceManager.QueueExists(QueueName)) { namespaceManager.CreateQueue(QueueName); } // Initialize the connection to Service Bus Queue _client = QueueClient.CreateFromConnectionString(connectionString, QueueName); return base.OnStart(); }