项目作者: SRoddis

项目描述 :
Build your App Brick by Brick
高级语言: C#
项目地址: git://github.com/SRoddis/BricksFx.git
创建时间: 2018-01-10T09:47:31Z
项目社区:https://github.com/SRoddis/BricksFx

开源协议:MIT License

下载


BricksFx

Build status Coverage Status


Build your Application Brick by Brick





Introduction

What is BricksFx?

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.

Why you should use

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.

How to use

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.

Installation

Install via nuget https://www.nuget.org/packages/BricksFx

  1. PM> Install-Package BricksFx

(Optional)

Install via nuget https://www.nuget.org/packages/BricksFx.Ninject

  1. PM> Install-Package BricksFx.Ninject

How to use

  1. Initialize BricksFx befor the Application.

    1. // Implement your ApplicationPlattform. In the ApplicationPlattform you can register your Bricks (Modules).
    2. public class ApplicationPlattform : AbstractPlattform
    3. {
    4. public ApplicationPlattform(IContainerAdapter containerAdapter)
    5. : base(containerAdapter)
    6. {
    7. }
    8. protected override IEnumerable<IBrick> ApplyBricks()
    9. {
    10. // Register your Bricks (Modules). How to create a Brick, please see "2. Create a Brick"
    11. return new IBrick[]
    12. {
    13. new CommunicatorBrick(),
    14. new ReceiverBrick()
    15. };
    16. }
    17. }
    1. public class Program
    2. {
    3. // Excample with Ninject
    4. var container = new StandardKernel();
    5. container.Bind<IApplication>().To<Application>();
    6. // BricksFx - Setup your DIContainerAdapter and Plattform
    7. container.Bind<IContainerAdapter>().To<NinjectContainerAdapter>();
    8. container.Bind<IPlattform>().To<ApplicationPlattform>();
    9. // BricksFx - StartUp the Plattform to register all the dependencies of the added Bricks
    10. var plattform = container.Get<IPlattform>();
    11. plattform.StartUp();
    12. // Run your application/webservice/webapp/app what ever! ;o)
    13. var app = container.Get<IApplication>();
    14. app.Run();
    15. }
  2. Create a Brick (Module) and define your dependencies.

    1. // Brick (Module)
    2. public class CommunictaionBrick : Brick
    3. {
    4. public override void BindDependencies()
    5. {
    6. Bind<ICommunicator, Communicator>();
    7. Bind<ISaySmth, HelloWorld>();
    8. }
    9. }
    10. public class ReceiverBrick : Brick
    11. {
    12. public override void BindDependencies()
    13. {
    14. Bind<IReceiver, ConsoleReceiver>();
    15. }
    16. }
    1. // Implementation of the Brick (Module)
    2. internal class Communicator : ICommunicator
    3. {
    4. private readonly ISaySmth _saySmth;
    5. public Communicator(ISaySmth saySmth)
    6. {
    7. _saySmth = saySmth;
    8. }
    9. public string Comunicate()
    10. {
    11. return _saySmth.Say();
    12. }
    13. }
    14. internal class ConsoleReceiver : IReceiver
    15. {
    16. public void Receive(string message)
    17. {
    18. Console.WriteLine(message);
    19. Console.ReadLine();
    20. }
    21. }
    1. // The defined dependencies can now be injected in the Application
    2. public class Application : IApplication
    3. {
    4. private readonly ICommunicator _communicator;
    5. private readonly IReceiver _receiver;
    6. public Application(ICommunicator communicator, IReceiver receiver)
    7. {
    8. _communicator = communicator;
    9. _receiver = receiver;
    10. }
    11. public void Run()
    12. {
    13. var message = _communicator.Comunicate();
    14. _receiver.Receive(message);
    15. }
    16. }
  1. 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

    License

    BricksFx is licensed under MIT. Refer to LICENSE.txt for more information.