Build your Application Brick by Brick
BricksFx
is the library to write code in small and handy modules that can be seed up quick and easy in new or old projects.
The idea is to keep your business code (logic) away from used frameworks (mvc, mvvm etc.) and dependency-injection-container,
to easy split up or reuse code of your application.
BricksFx
is a small library to provide flexebility. It is not a heavy application framework.
From my experience as a developer you often work in a project that starts with a simple application. Depending on the project and its needs, the application starts growing. Domains and logic will be added and quite often the application becoming a monolithic application. At some point of the development you might determine the need of scaling. Monolithic applications are bad when it comes to scaling.
In this case BricksFx
support you to be flexible and move your code from one application to another.
Define a Brick
for a module you want to write. Bind the dependencies you want to expose and seed
up an IPlattform
where you can stick new and old Bricks
(modules) together.
It should be as easy as building LEGO-Bricks.
Install via nuget https://www.nuget.org/packages/BricksFx
PM> Install-Package BricksFx
(Optional)
Install via nuget https://www.nuget.org/packages/BricksFx.Ninject
PM> Install-Package BricksFx.Ninject
-
Initialize
BricksFx
befor theApplication
.// Implement your ApplicationPlattform. In the ApplicationPlattform you can register your Bricks (Modules). public class ApplicationPlattform : AbstractPlattform { public ApplicationPlattform(IContainerAdapter containerAdapter) : base(containerAdapter) { } protected override IEnumerable<IBrick> ApplyBricks() { // Register your Bricks (Modules). How to create a Brick, please see "2. Create a Brick" return new IBrick[] { new CommunicatorBrick(), new ReceiverBrick() }; } }
public class Program { // Excample with Ninject var container = new StandardKernel(); container.Bind<IApplication>().To<Application>(); // BricksFx - Setup your DIContainerAdapter and Plattform container.Bind<IContainerAdapter>().To<NinjectContainerAdapter>(); container.Bind<IPlattform>().To<ApplicationPlattform>(); // BricksFx - StartUp the Plattform to register all the dependencies of the added Bricks var plattform = container.Get<IPlattform>(); plattform.StartUp(); // Run your application/webservice/webapp/app what ever! ;o) var app = container.Get<IApplication>(); app.Run(); }
-
Create a Brick (Module) and define your dependencies.
// Brick (Module) public class CommunictaionBrick : Brick { public override void BindDependencies() { Bind<ICommunicator, Communicator>(); Bind<ISaySmth, HelloWorld>(); } } public class ReceiverBrick : Brick { public override void BindDependencies() { Bind<IReceiver, ConsoleReceiver>(); } }
// Implementation of the Brick (Module) internal class Communicator : ICommunicator { private readonly ISaySmth _saySmth; public Communicator(ISaySmth saySmth) { _saySmth = saySmth; } public string Comunicate() { return _saySmth.Say(); } } internal class ConsoleReceiver : IReceiver { public void Receive(string message) { Console.WriteLine(message); Console.ReadLine(); } }
// The defined dependencies can now be injected in the Application public class Application : IApplication { private readonly ICommunicator _communicator; private readonly IReceiver _receiver; public Application(ICommunicator communicator, IReceiver receiver) { _communicator = communicator; _receiver = receiver; } public void Run() { var message = _communicator.Comunicate(); _receiver.Receive(message); } }
-
Please have a look at the Demo. If you have questions, send me a message or open a issue in this repository.
Copyright © 2018 Sean Roddis
BricksFx is licensed under MIT. Refer to LICENSE.txt for more information.