Skip to content

Easy Component and Application Parameterisation for C#

Notifications You must be signed in to change notification settings

SuuBro/Paramulate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Paramulate

A framework for parameterising C# components and applications

Table of Contents

Summary

Paramulate is a powerful framework for parameterising C# code, from command line arguments, programmatic defaults, config files, databases or any other source you like! It allows you to easily print your parameters to an output stream and see where individual settings came from.

Philosophy

Paramulate creates a culture around the design of your components with respect to parameterisation. It hopes to inspire developers to follow these mantras when writing applications and libraries:

  • Separate logic: Paramulate encourages developers to separate business logic from configuration and settings, behaviour should be agnostic to the input mechanism
  • Author knows best: sensible defaults should be provided by developers to make using their component easier
  • Customer knows better: advanced users what to change everything, and they know their use-case best
  • Seeing is believing: you should be able to easily see the inputs to the code
  • I'm no Sherlock: tracking down the source of parameters should be trivial
  • Consistency without constraint: Paramulate encourages consistency, but doesn't force a dependency

Example

Given the code:

    public interface IUserDatabaseParams
    {
        [Default("server=PROD;Database=UserDb")]
        string ConnectionString { get; }
        
        [Default("2")]
        int NumRetries { get; }
    }
    
    public interface ITranslatorParams
    {
        [Default("AutoDetect")]
        [Alias("i", "input-language", "(Optional) Use this to choose the input language. " +
                                      "Either 'AutoDetect' or a supported language (e.g. 'Spanish')")]
        string InputLanguage { get; }
        
        [Alias("o", "output-language", "Use this to choose the output language. " +
                                       "Any supported language (e.g. 'Mandarin')")]
        string OutputLanguage { get; }
        
        [Override("NumRetries", "3")]
        IUserDatabaseParams UserDb { get;}
    }
    
    public class TranslatorApp
    {
        public static int Main(string[] args)
        {
            var builder = ParamsBuilder<ITranslatorParams>.New("App",
                new CommandLineValueProvider(args)
            );
            var parameters = builder.Build();
            builder.WriteParams(parameters, Console.Out);
            // ... App Code ...
            return 0;
        }
    }

and the command

TranslatorApp.exe -o English --App.UserDb.ConnectionString "Server=TEST;Database=UserDb7E2A"

You would have the following parameter object initilaised for you:

App:
  InputLanguage: "AutoDetect" (From Default)
  OutputLanguage: "English" (From Command Line)
  UserDb:
    ConnectionString: "Server=TEST;Database=UserDb7E2A" (From Command Line)
    NumRetries: 3 (From Override on UserDb)

Features

TODO