Showing posts with label github. Show all posts
Showing posts with label github. Show all posts

Sunday, November 22, 2020

Delphi Event Bus 2.0 is here

 Hi folks,

I have been involved in the Ekon 24 conference and I held a session: Decoupling your application architecture using Delphi Event Bus. There I presented the 2.0 version of DEB and all the news along with this version:

  • Added new Interface based mechanism to declare and handle events
  • Added channels for simple string-based events
  • DEB available on GetIt 





Interface based mechanism

The new mechanism relies on the fact that an event must be an interface or its descendants:




This new architecture brings a great benefit in terms of memory management, because Interfaces are reference counted in Delphi. 

Breaking changes

  • Differently from the previous versions a subscriber method can only have 1 parameter that is an IInterface or descendants. 
    • You should change every Subscriber method to be compliant with that principle
  • On the same line of the previous one, because events now are interfaces EventBus.Post method can accept only an interface as parameter now
    • You should change every EventBus.Post method and pass it an interface - if you were using object with no interfaces 

Channels 

A very nice addition is the possibility to subscribe and post simple string-based events:  



Other improvements

  • Improved the internal post mechanism removing the CloneEvent due to the fact events were objects
  • Removed external sources needed because of the point above


How can I get it?

Since the version 1.5 Delphi Event Bus is available in GetIt (the Delphi integrated package manager):

You can also choose to download/copy/fork the library from github: https://github.com/spinettaro/delphi-event-bus

or downloading directly the release from here: https://github.com/spinettaro/delphi-event-bus/releases/tag/v2.0

Hope you find this version full of interesting features for you! 

Enjoy it!!



Tuesday, January 8, 2019

Delphi Flux application architecture

A good application architecture

Finding a good application architecture is not easy, but defining an architecture for your application is important: like it or not, every application is going to have an architecture.
There is no such thing as the Best Architecture, but there is the Best Architecture for your current application! (finish the project on time, with quality, less bugs as possible - no bugs preferred :) - and easy collaboration with your teammates).
Flux is the application architecture that Facebook uses to structure client-side web applications, is very simple to understand and there is almost no code for it. It's just a way to do things.
It’s a Clean Architecture so it’s not intended only for web apps, but its features and simplicity will allow us to adapt it very well to other kind of projects.
I believe Flux is very good choice.

Delphi Flux

Base Flux concepts, I created a project on Github Delphi-Flux-Seed. This project is an application skeleton to apply Flux concepts in Delphi applications. You can use it to quickly bootstrap your Delphi application. 

About Delphi Flux I held a session at CodeRage 2018, so you can watch the replay of that session at this link. Here are the slides of my presentation at CodeRage 2018:

Sunday, September 3, 2017

Delphi Entities Validators

How many of you use business objects in your applications?
How many of you use an ORM ?
In this case... how do you validate entities in your applications ?
  1. In a not very elegant way 
  2. The classic is IsValid() method on BO
  3. Something else?
  4. Validation inside or outside entities?
  5. How about different context?
Entity validation can be a tricky beast! From bit Time Professionals Lab... Delphi Entities Validators ! It is a small framework that provides an easy and ready-to-use interface for entities validation.
You can achieve Entities validation in three ways:

  1. Simple validation
  2. Attribute validation
  3. Container validation
The innovative solution of this framework is the Context: in the most case when you have to validate an Entity you have a class explosion for different situations. For example if you have to validate an entity that represents a User you have different Object classes for different context: one class for Login, one for registration etc... because the field that you have to validate are different in these different situations. With Context, the things going to get easier because you can maintain one Object Class and choose wich fields and when to validate them.
So let's go see the code!

Simple Validation

In Simple Validation mode you have to implements the IValidator interface, that use generics, replacing the placeholder with your class. The interface provides Validate method that you must implement, and here you have to write your validation logic. This method returns an IValidationResult wich is composed by:
  • IsValid - returns a boolean that represents the success or failures validation
  • BrokenRules - returns an array of string that represents the broken rules



Attributes Validation

In Attributes Validation you can use a ready-to-use attributes to validate the field of your BO (or create yours). This is first example where Context avoids you a lot of code:


In this case the affected fields are the only that have the context 'AttributesValidation'.

Container Validation

In Container Validation you can use the Simple Validation mechanism adding all the benefits of using a container and context mechanism:


Delphi Entities Validation can be a great ally in writing code, saving you time and code!