https://github.com/hashload/injectorbr
APPInjector Brasil for Delphi (Isaque Pinheiro)
https://github.com/hashload/injectorbr
delphi dependency-injection framework interfaces lazarus
Last synced: 4 months ago
JSON representation
APPInjector Brasil for Delphi (Isaque Pinheiro)
- Host: GitHub
- URL: https://github.com/hashload/injectorbr
- Owner: HashLoad
- License: gpl-3.0
- Created: 2023-03-15T15:25:09.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-26T17:09:33.000Z (over 1 year ago)
- Last Synced: 2024-04-13T21:53:28.257Z (about 1 year ago)
- Topics: delphi, dependency-injection, framework, interfaces, lazarus
- Language: Pascal
- Homepage: https://www.isaquepinheiro.com.br
- Size: 1.05 MB
- Stars: 15
- Watchers: 6
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# InjectorBr Framework for Delphi
InjectorBr is a dependency injection framework for Delphi applications. Dependency injection is a software design pattern that allows decoupling components of an application, making them more modular and easier to maintain. With it, developers can easily create modular and flexible applications, avoiding tightly coupled dependencies and reducing code complexity. The framework also includes features for managing component lifecycle.
## 🏛 Delphi Versions
Embarcadero Delphi XE and higher.## ⚙️ Install
Installation using the [`boss install`](https://github.com/HashLoad/boss) command:
```sh
boss install "https://github.com/HashLoad/injectorbr"
```## :hammer: Dependency injection features with InjectorBr
:heavy_check_mark: `Recurso 1`: ```Injector.Register``` to (Class)
:heavy_check_mark: `Recurso 2`: ```Injector.RegisterLazy``` to (Class for LazyLoad)
:heavy_check_mark: `Recurso 3`: ```InjectorInterface``` to (Interface)
In addition to these three methods, the framework also offers the feature of creating a new instance of a class that is already registered. To do this, simply use the command:
:heavy_check_mark: ```Injector.New``` for (New Instance)
## ⚡️ How to use
#### Using with interfaces
```Delphi
{ /////////////////////// Registering ///////////////////////// }unit dfe.engine.acbr;
interface
uses
SysUtils,
dfe.engine.interfaces;type
TDFeEngineACBr = class(TInterfacedObject, IDFeEngine)
public
class function New: IDFeEngine;
procedure Execute;
end;implementation
{ TDFeEngineACBr }
procedure TDFeEngineACBr.Execute;
begin
raise Exception.Create('DFe Engine ACBr');
end;class function TDFeEngineACBr.New: IDFeEngine;
begin
Result := Self.Create;
end;initialization
InjectorBr.RegisterInterface;end.
{ /////////////////////// Recovering ///////////////////////// }
unit global.controller;
interface
uses
DB,
Rtti,
Classes,
SysUtils,
Controls,
global.controller.interfaces,
dfe.engine.interfaces;type
TGlobalController = class(TInterfacedObject, IGlobalController)
private
FDFeEngine: IDFeEngine;
public
constructor Create;
procedure DFeExecute;
end;implementation
uses
app.injector;{ TGlobalController }
constructor TGlobalController.Create;
begin
inherited;
FDFeEngine := InjectorBr.GetInterface;
end;procedure TGlobalController.DFeExecute;
begin
FDFeEngine.Execute;
end;end.
```
#### Using with classes```Delphi
{ /////////////////////// Registering ///////////////////////// }unit dfe.engine.acbr;
interface
uses
SysUtils;type
TDFeEngineACBr = class
public
procedure Execute;
end;implementation
{ TDFeEngineACBr }
procedure TDFeEngineACBr.Execute;
begin
raise Exception.Create('DFe Engine ACBr');
end;initialization
InjectorBr.RegisterSington;end.
{ /////////////////////// Recovering ///////////////////////// }
unit global.controller;
interface
uses
DB,
Rtti,
Classes,
SysUtils,
Controls,
global.controller.interfaces,
dfe.engine.acbr;type
TGlobalController = class(TInterfacedObject, IGlobalController)
private
FDFeEngine: TDFeEngineACBr;
public
constructor Create;
procedure DFeExecute;
end;implementation
uses
app.injector;{ TGlobalController }
constructor TGlobalController.Create;
begin
inherited;
FDFeEngine := InjectorBr.Get;
end;procedure TGlobalController.DFeExecute;
begin
FDFeEngine.Execute;
end;end.
```#### Using with class and lazyLoad
```Delphi
{ /////////////////////// Registering ///////////////////////// }unit dfe.engine.acbr;
interface
uses
SysUtils;type
TDFeEngineACBr = class
public
procedure Execute;
end;implementation
{ TDFeEngineACBr }
procedure TDFeEngineACBr.Execute;
begin
raise Exception.Create('DFe Engine ACBr');
end;initialization
InjectorBr.RegisterLazy;end.
{ /////////////////////// Recovering ///////////////////////// }
unit global.controller;
interface
uses
DB,
Rtti,
Classes,
SysUtils,
Controls,
global.controller.interfaces,
dfe.engine.acbr;type
TGlobalController = class(TInterfacedObject, IGlobalController)
private
FDFeEngine: TDFeEngineACBr;
public
constructor Create;
procedure DFeExecute;
end;implementation
uses
app.injector;{ TGlobalController }
constructor TGlobalController.Create;
begin
inherited;
FDFeEngine := InjectorBr.Get;
end;procedure TGlobalController.DFeExecute;
begin
FDFeEngine.Execute;
end;end.
```## ✍️ License
[](https://opensource.org/licenses/LGPL-3.0)## ⛏️ Contribution
Our team would love to receive contributions to this open-source project. If you have any ideas or bug fixes, feel free to open an issue or submit a pull request.
[](https://github.com/HashLoad/ormbr/issues)
To submit a pull request, follow these steps:
1. Fork the project.
2. Create a new branch. (`git checkout -b my-new-feature`)
3. Make your changes and commit. (`git commit -am 'Adding new functionality'`)
4. Push the branch. (`git push origin my-new-feature`)
5. Open a pull request.## 📬 Contact
[](https://t.me/hashload)## 💲 Donation
[](https://pag.ae/bglQrWD)