Friday, February 27, 2015

What is unit of work and relationship with CQRS/Event Sourcing?


But I think this pattern is not applicable for CQRS/Event Sourcing, because SAGA is the way to deal with transaction in CQRS/Event Sourcing.

Wednesday, February 25, 2015

What is Aggregate in DDD?

From Eric Evans book DDD Page 90
An AGGREGATE is a cluster of associated objects that we treat as a unit for the purpose of data changes. Each AGGREGATE has a root and a boundary. The boundary defines what is inside the AGGREGATE. The root is a single specific ENTITY contained in the AGGREGATE. The root is the only member of the AGGREGATE that outside objects are allowed to hold references to, although objects within the boundary may hold references to each other. ENTITIES other than the root have local identity, but it only needs to be unique within the aggregate, since no outside object can ever see it out of the context of the root ENTITY.

By Martin Fowler
a cluster of domain objects that can be treated as a single unit.

Monday, February 23, 2015

How to enable intellisense in Visual Studio after remove reSharper?

My Visual Studio inellisense stopped working after removed ReSharper(ReSharper is so slow).

The solution:
Tools->Options->Text Editor->All Languages->General
Turn off "Auto list members", and "Parameter information"
And turn on again.

Friday, February 20, 2015

How to get stream name list from Event Store?

Better idea from Greg Young

Greg Young 

Feb 20 (3 days ago)
to event-store 
What will happe  to your projection with 100m streams?

Original test code:

        $init: function(s,e) { return {streanList:"", count:0} },
        $any : function(s,e) {
            if (!s.streanList){
                s.streanList =" ";
            if (s.streanList.indexOf(e.streamId) < 0){
               s.streanList = s.streanList + e.streamId +",";


How to count event number in one stream?

        $init: function() {
           return { count: 0 }
        $any : function(s,e) { return s + 1;}

How to count event number in Event Store?

        $init: function(s,e) { return 0;},
        $any : function(s,e) { return s + 1;}

Wednesday, February 18, 2015

How to solve problem "Read access denied for stream" while reading events from event store?

Get this error on following line:
var event = connection.ReadStreamEventsForwardAsync(streamid, 0, 1, false).Result;

Need to add credential for reading
var event = connection.ReadStreamEventsForwardAsync(streamid, 0, 1, false,  new UserCredentials("admin", "changeit")).Result;

How to solve problem "System.AggregateException: One or more errors occured ---> EventStore.ClientAPI.Exceptions.RetriesLimitReachedException" when try to connect to write event to Event Store?

This error happened  after downloaded Event Store 3.0.1 and tried following code for the testing

            string serverIpaddress = "";
            var connection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Parse(serverIpaddress), 2113));
            var myEvent = new EventData(Guid.NewGuid(), "testEvent", false,
                                        Encoding.UTF8.GetBytes("some data1"),
                                        Encoding.UTF8.GetBytes("some metadata"));
                               ExpectedVersion.Any, myEvent).Wait();

On line of AppendToStreamAsync, exception throws:
 "System.AggregateException: One or more errors occured ---> EventStore.ClientAPI.Exceptions.RetriesLimitReachedException"

Cause: .NET API of Event Store goes by TCP port, which default value is 1113, http port number is 2113 by default.

Just change to            
          var connection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Parse(serverIpaddress), 1113));


Thursday, February 12, 2015

How to check TcpListener is listening?

In TcpListener class, there is a property called Active but it a proctected one.

Create a sub class from TcpListener, and expose this property by yourself.

Code example:
    public class Listener : TcpListener
        public Listener(int portNumber): base(IPAddress.Any, portNumber) {}
        public bool IsAcitve
            get { return this.Active; }

Wednesday, February 11, 2015

What is projection in event sourcing

Projection is about deriving current state from the stream of events

Quote from Ralph Johnson: Before software can be reusable it first has to be usable.

Reusable software is not number one priority anymore. So why want to design software to be reusable.

Tuesday, February 10, 2015

Reading about CQRS and event souring

Exploring CQRS and Event Sourcing

Applying CQRS and Event Sourcing in Microsoft .NET Applications TechEd Europe 2014

Monday, February 9, 2015

What is bounded context?

From DDD website:
[[Bounded Context]] The delimited applicability of a particular model. BOUNDING CONTEXTS gives team members a clear and shared understanding of what has to be consistent and what can develop independently.

From Martin Folwer:
Bounded Context is a central pattern in Domain-Driven Design. It is the focus of DDD's strategic design section which is all about dealing with large models and teams. DDD deals with large models by dividing them into different Bounded Contexts and being explicit about their interrelationships.

The term bounded context comes from Eric Evans' book. In brief, Evans introduces this concept as a way to decompose a large, complex system into more manageable pieces; a large system is composed of multiple bounded contexts. Each bounded context is the context for its own self-contained domain model, and has its own ubiquitous language. You can also view a bounded context as an autonomous business component defining clear consistency boundaries: one bounded context typically communicates with another bounded context by raising events.

From "DDD: The Bounded Context Explained"

really Explained?

Same question at

Conclusion:  bounded context is a fence.

How come a key concept in DDD is with so many ambiguous definitions?

Procedural vs OO, Anthropomorphism Gone Wrong: Poor Motivating Example for OOP

Procedural vs OO with code example

Thursday, February 5, 2015

How to solve Visual Studio git push problem "You cannot publish local branch master to the remote repository origin"?

Error happened:
When I created a local git repository and tried to push to remote repository, got following error:

"You cannot publish local branch master to the remote repository origin because a branch with the same name already exists there. You might want to rename your local branch and try again"

- Install 3rd party git tool
- Add remote repository in GitUI
- Click push, and select "remote repository"