DSL for code contracts
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
examples
src
.gitignore
README.org
project.clj

README.org

CQRS DSL Tool

This is a simple Clojure utility which takes aggregate specifications as input and generates C# files for command and event classes (serializable with protobuf).

It is a small step-up from Lokad Code DSL which did the same thing but was based on ANTLR for parsing of the original ddd files to AST. This tool uses edn data notation which can be directly used as AST. We simply prettify this AST a little (e.g. via resolving field shortcuts) to transform it into Semantic DSL Model and then generate C# code from it.

Examples

For example, given a file trivial.edn, it will generate trivial.cs.

Here is the snippet. This portion below:

(cmd UpdateUserRoles (:user :roles))

will translate to this snippet (extra fields are shared between multiple messages and are declared at a higher level):

[DataContract(Namespace = "trivial.msg")]
public partial class UserRolesUpdated : IAccountEvent
{
    [DataMember(Order = 1)] public TenantId TenantId { get; private set; }
    [DataMember(Order = 2)] public UserId UserId { get; private set; }
    [DataMember(Order = 3)] public string UserName { get; private set; }
    [DataMember(Order = 4)] public string[] Roles { get; private set; }
    [DataMember(Order = 5)] public DateTime DateUtc { get; private set; }
  
    UserRolesUpdated ()
    {
        Roles = new string[0];
    }
  
    public UserRolesUpdated (TenantId tenantId, UserId userId, string userName, string[] roles, DateTime dateUtc)
    {
        if ( tenantId == null ) throw new ArgumentNullException( "tenantId" );
        if ( userId == null ) throw new ArgumentNullException( "userId" );
        if ( userName == null ) throw new ArgumentNullException( "userName" );
        TenantId = tenantId;
        UserId = userId;
        UserName = userName;
        Roles = roles;
        DateUtc = dateUtc;
    }
}

For an annotated example see simple.edn.

Building and running

You will need lein build tool.

To run examples, regenerating all cs files:

$ lein run examples

To create a single jar file:

$ lein uberjar

This will create an dsl-version-commit.uber.jar file in the targets folder. This file could then be executed via:

$ java -jar target/dsl-0.1.0-a8a191a.uber.jar examples

Or you could copy it to any machine with Java and run there.