Skip to content

Latest commit

 

History

History
115 lines (91 loc) · 6.1 KB

README.md

File metadata and controls

115 lines (91 loc) · 6.1 KB

Cormo

Cormo is a .NET application development framework that brings both Spring and the CDI (Contexts and Dependency Injection) spec from Java EE (specifically its implementation by [JBoss Weld] (http://weld.cdi-spec.org)) into .NET development.

Cormo's main objectives is Productivity.

  • A simpler way for application components to interact. Traditional layered architecture is often rigidly bloated with vertical stacks of indirections that become heavy and unmanageable as your codebase grows. JavaEE 6 introduced CDI as the standard glue for independent parts of your application and eliminates several layers of indirections and abstractions, resulting in a more organic and pragmatic layering. It makes many common .NET patterns and "best-practices" superfluous (interfaces, repository, read/write services, commands, handlers, event-bus). Instead the magic words are YAGNI and KISS. (Read#1, Read#2)
  • Remove ceremonies out of writing code. Cormo aims to provide an environment to develop and host modules that you can pick and plug onto your application to speed up development and take care of plumbing works so you don't have to. Writing code shouldn't be so hard: configuring IoC, ORM, auditing, security, messaging, events, logging, transactions, scheduling, health-monitoring, etc, I want to only need to say so and they just happen. Spring-Boot is a great framework that currently offers such capability, and Cormo tries to bring it to .NET environment.

Getting Started

To start a new web project, start an empty ASP.NET project (do not pick any template e.g. MVC or WebAPI. They're bloated!).

Then NuGet:

Install-Package Cormo.Web

This does not add/modify any file in your project. At runtime Cormo.Web will wire up ASP.NET plumbing for you with sensible defaults (e.g. OWIN, WebAPI, Dependency Injections) so no configuration or setup code needed.

Now with the still empty project, go ahead and write your first controller:

[RestController]
public class MyController
{
  [Route("/hello")]
  public string Hello() { return "Hello world"; }  
}

That was the only file you need to have in the project. Now build and run it on the browser.

Note that extending ApiController or IHttpController is optional. At runtime Cormo.Web will inject that for you (see: Mixins). This is to promote lightweight POCOs and dependency injection principles, keeping testability and sanity of your code. ApiController class carries heavy infrastructural baggage that goes agains the spirit of CDI, so we encourage to keep that away from your POCO and let Cormo.Web take care of wiring that up from behind the stage.

Dependency Injection

Dependency Injection is fully configured for you. No additional setup needed. Example:

[RestController]
public class MyController
{
  [Inject] Greeter _greeter;   // <- Here
  
  [Route("/hello")]
  public string Hello() { return _greeter.Greet("world"); }  
}

public class Greeter
{
  public string Greet(string name) { return "Hello " + name; }
}

Of course you could also use interfaces but it's not required. You could also put [Inject] on constructors, fields, methods, and properties. Open generic types and constraints are also supported (TODO: example).

TODO: explain [Inject], [Produce], [Qualifier], [PostConstruct], [PreDeploy]

Tweaking Your Plumbing

Cormo modules (e.g. Cormo.Web in this case) configure your environment with sensible defaults. If you do however want to deviate from the provided default, you can always override it by declaring your own components. For instance, to override WebApi's HttpConfiguration settings:

public class WebApiConfiguration
{
  [Produces] HttpConfiguration GetConfiguration()
  {
    return new HttpConfiguration( /* ... */ );
  }
}

Here you redefine your own complete HttpConfiguration as you wish. However, in many cases you're probably happy with the default values except a few things you want to tweak. In this case, rather than redefining the component you can simply modify the existing default.

[Configuration]
public class WebApiConfiguration
{
  [Inject] void InitConfiguration(HttpConfiguration config)
  {
     // Do something with config
  }
}

See "Dependency Injection" for more.

Note: Marking your class with [Configuration] ensures your class gets executed before the application starts.

Further Reading

The current state of Cormo's documentation is pretty sad. Well luckily the specs and frameworks that Cormo is based on come with excellent documentations. A lot in those documentations are applicable to Cormo (or what Cormo will come to be), so go and check them out. Just replace the word "Bean" with "Component".

More

TODO: Scopes (Dependent, Singleton, RequestScoped, ResponseScoped, custom scopes)

TODO: Decorator and Interceptor

TODO: Mixins

TODO: Creating modules

TODO: Event and [Observes]

TODO: Scheduled tasks

TODO: Cormo.Web.Security

TODO: Messaging

TODO: Unit-testing