Quick Start

michael-freidgeim-webjet edited this page Nov 9, 2017 · 8 revisions
var store = Wireup.Init()
  .UsingSqlPersistence("Name Of EventStore ConnectionString In Config File")
  .HookIntoPipelineUsing(new[] { new AuthorizationPipelineHook() })
    // Example of NServiceBus dispatcher: https://gist.github.com/1311195
    .DispatchTo(new My_NServiceBus_Or_MassTransit_OrEven_WCF_Adapter_Code())

using (store)
  // some business code here
  using (var stream = store.CreateStream(myMessage.CustomerId))
    stream.Add(new EventMessage { Body = myMessage });
  using (var stream = store.OpenStream(myMessage.CustomerId, 0, int.MaxValue))
    foreach (var @event in stream.CommittedEvents)
      // business processing...

If you are using an inversion of control container, registering the store as Single Instance should be safe, as it is designed to be thread-safe (see IStoreEvents).

For a more complete example, please see NEventStore.Example.

A quick explanation of some of the Wireup options

  • LogToOutputWindow()

    Turns on logging to the debugger's "Output" window (using Trace.WriteLine). Alternatives are LogToConsoleWindow or simply LogTo, which you can use to implement your own logging or wire your preferred logging framework.|

  • UsingInMemoryPersistence()

    Makes NEventStore use an in-memory data store, useful for testing.

  • UsingSqlPersistence("EventStore")

    Makes NEventStore use the SQL persistence engine, which is probably the most "done" one currently. As usual, the connection string is by default read from the app.config or web.config; you can also supply your own IConnectionFactory.

  • WithDialect(new MsSqlDialect())

    Enables the SQL persistence engine to use MSFT SQL Server.

  • WithStreamIdHasher(s => s)

    Defines a different Stream ID hashing algorithm.

    The SQL persistence engine stores stream IDs in two different forms: the long, original one (with up to 1000 characters), and a shortened, "hashed" one (with up to 40 characters). The shortened one is used to implement efficient, indexed access in SQL Server. By default, SHA-1 indexing is used for hashing.

    If the used stream IDs aren't longer than 40 characters (e.g., if they are string-converted Guids), an identity hashing algorithm can be supplied (s => s). This makes the stored Stream IDs human-readable.

  • EnlistInAmbientTransaction()

    Enables two-phase commit. By default, NEventStore will suppress surrounding TransactionScopes so that all of its operations run in a dedicated, separate transaction. This option changes the behavior so that NEventStore enlists in a surrounding TransactionScope, if there is any.

    Do not use this unless you really need it - the default is to not enlist in ambient transactions.

    Note that this option has undesired side effects that you might need to work around, at least with the SQL Persistence: https://github.com/NEventStore/NEventStore.Persistence.SQL/issues/12 and https://github.com/NEventStore/NEventStore/issues/414.

  • InitializeStorageEngine()

    Causes the persistence engine to initialize it's schema. E.g., the SQL persistence engine with the MsSqlDialect will execute something like this:

    IF EXISTS(SELECT * FROM sysobjects WHERE name='Commits' AND xtype = 'U') RETURN; CREATE TABLE [dbo].[Commits] ...

  • TrackPerformanceInstance("instanceName")

    This enables NEventStore performance counters with the given instance name. E.g., "Total commits", "Commits/s", etc.

  • UsingJsonSerialization()

    Makes NEventStore serialize your events using an internalized version of JSON.NET. Alternatives are UsingBinarySerialization, UsingBsonSerialization, or custom serialization.

  • Compress()

    Enables Gzip compression of serialized event data.

  • EncryptWith(EncryptionKey)

    Enables encryption of serialized event data using the RijndaelManaged BCL class and the given key.

  • HookIntoPipelineUsing(new[] {new AuthorizationPipelineHook()})

    Represents an extension point into NEventStore, e.g., to intercept commits, etc, e.g., to check whether the current user is authorized to read or write a specific stream.

  • UsingSynchronousDispatchScheduler(), DispatchTo(new DelegateMessageDispatcher(DispatchCommit))

    Configures how events will be "dispatched" to "the event bus". Alternative is "UsingAsynchronousDispatchScheduler". This is deprecated and should no longer be used because it:

    • assumes a single receiver,
    • doesn't support read model catch-up, and
    • doesn't ensure event ordering during dispatch (requiring the receiver to resequence messages).

    Use Polling Client instead, which solves these issues.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.