Friday, February 27, 2015

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

See
http://martinfowler.com/eaaCatalog/unitOfWork.html



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.
Reference:
https://msdn.microsoft.com/en-us/library/jj591569.aspx

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.
http://martinfowler.com/bliki/DDD_Aggregate.html

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 gregoryyoung1@gmail.com 

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




Original test code:

fromAll().
    when({
        $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 +",";
               s.count++;
            }
        }
    })

Reference:
http://dbs-are-fn.com/2013/interview_greg_young_event_store/

How to count event number in one stream?

fromStream("streamName")
   .when({
        $init: function() {
           return { count: 0 }
        },
        $any : function(s,e) { return s + 1;}
  })

How to count event number in Event Store?

fromAll().
    when({
        $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 = "127.0.0.1";
            var connection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Parse(serverIpaddress), 2113));
            connection.ConnectAsync().Wait();
            var myEvent = new EventData(Guid.NewGuid(), "testEvent", false,
                                        Encoding.UTF8.GetBytes("some data1"),
                                        Encoding.UTF8.GetBytes("some metadata"));
            connection.AppendToStreamAsync("test-stream",
                               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));

Reference
https://groups.google.com/forum/#!topic/event-store/5uWEqybibw8

Thursday, February 12, 2015

How to check TcpListener is listening?

In TcpListener class, there is a property called Active but it a proctected one.
https://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.active(v=vs.110).aspx

Solution:
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
Reference:
http://abdullin.com/post/event-sourcing-projections/

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
https://msdn.microsoft.com/en-us/library/jj554200.aspx

Applying CQRS and Event Sourcing in Microsoft .NET Applications TechEd Europe 2014
https://www.youtube.com/watch?v=z5FPkCgcH4M

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.
http://dddcommunity.org/resources/ddd_terms/

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.
http://martinfowler.com/bliki/BoundedContext.html

From MSDN
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.
https://msdn.microsoft.com/en-us/library/jj591575.aspx

From "DDD: The Bounded Context Explained"
http://www.sapiensworks.com/blog/post/2012/04/17/DDD-The-Bounded-Context-Explained.aspx

really Explained?

Same question at
http://programmers.stackexchange.com/questions/237513/what-in-reference-to-ddd-is-a-bounded-context

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
http://loup-vaillant.fr/articles/anthropomorphism-and-oop

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"

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