Code Monkey home page Code Monkey logo

messagegeneration's Introduction

Message Generation

This prototype explores generation of data classes for messaging between applications. It demonstrates

  1. Use of dependency injection to autowire language specific code generators
  2. Use of a templating library
  3. Generation a hash for each message schema embedded in the generated code

Dependency Injection

Language specific code generators implement the ILanguageCodeGenerator interface. The constructor for CodeGenerator requires an enumerable of ILanguageCodeGenerator which Ninject populates with all implementations bound to the interface.

public CodeGenerator(IEnumerable<ILanguageCodeGenerator> languageCodeGenerators)

Binding is done using ninject.extensions.conventions.

kernel.Bind(x => x
    .FromThisAssembly()
    .SelectAllClasses()
    .BindAllInterfaces());

Templating

The Handlebars.net library is used for templating. Templates for generating C# code is found in directory CsTemplates.

namespace ToDo
{
    public class {{Name}}
    {
		public static readonly string Schema = "{{Schema}}";

		{{#each Properties}}
		public {{Type}} {{Name}} { get; set; }
		{{/each}}
    }
}

Message definitions from the Model namespace are decorated to add functionality specific to C# code generation. This is done by classes CsMessage and CsProperty.

Schema Hash

The schema hash is calculated in the CsMessage decorator constructor.

var json = JsonConvert.SerializeObject(message);
var bytes = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(json));
Schema = bytes.Select(b => b.ToString("X2")).Aggregate((s1, s2) => s1 + s2);

If a Message definition changes this will change the hash. If a Message includes a property of type Message and that type changes the hash of the parent will change.

messagegeneration's People

Contributors

dangerousdarlow avatar

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.