GithubHelp home page GithubHelp logo

dsl's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.