fiberdi

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 8 Imported by: 0

README

Fiber Dependency Injection

FiberDI uses Dependency Injection in conjunction with the practices used at ClickCode.dev

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(module *Module, configs ...fiber.Config) *fiber.App
appModule := &fiberdi.Module{}

New creates a new Fiber named instance.

app := fiberdi.New(appModule)

You can pass optional configuration options by passing a Config struct:

app := fiber.New(appModule, fiber.Config{
    Prefork: true,
    ServerHeader: "Fiber",
})

ATTENTION: DisableStartupMessage is true and cannot be changed

Types

type IController

type IController interface {
	// Routes is needed to create routes automatically
	//
	//	type YourController struct {}
	//
	// 	func (controller YourController) Routes(app *fiber.App) *fiber.App {
	//  	app.Get("/", DoSomething)
	//		return app
	//	}
	Routes(*fiber.App) *fiber.App
}

type IModule

type IModule interface {
	// contains filtered or unexported methods
}

type Module

type Module struct {
	// Controller needs function Routes
	//
	//	type YourController struct {}
	//
	// 	func (controller YourController) Routes(app *fiber.App) *fiber.App {
	//  	app.Get("/", DoSomething)
	//		return app
	//	}
	//
	//	appModule := &fiberdi.Module{
	//		Controllers: []fiberdi.IController{
	//			&YourController{},
	//		},
	//	}
	Controllers []IController

	// Injectables persist all your dependencies
	//
	//	type YourService struct {}
	//
	// 	func (controller YourService) DoSomething(ctx *fiber.Ctx) error {
	//  	return ctx.JSON("OK")
	//	}
	//
	//	type YourController struct {
	//		YourService *YourService
	//	}
	//
	// 	func (controller YourController) Routes(app *fiber.App) *fiber.App {
	//  	app.Get("/", controller.YourService.DoSomething)
	//		return app
	//	}
	//
	//	appModule := &fiberdi.Module{
	//		Controllers: []fiberdi.IController{
	//			&YourController{},
	//		},
	//		Injectables: []interface{}{
	//			&YourService{},
	//		},
	//	}
	Injectables []interface{}

	// You can create submodules
	//
	//	type CatService struct {}
	//
	// 	func (controller CatService) DoSomething(ctx *fiber.Ctx) error {
	//  	return ctx.JSON("Cat")
	//	}
	//
	//	type CatController struct {
	//		CatService *CatService
	//	}
	//
	// 	func (controller CatController) Routes(app *fiber.App) *fiber.App {
	//  	app.Get("/", controller.CatService.DoSomething)
	//		return app
	//	}
	//
	//	catModule := &fiberdi.Module{
	//		Controllers: []fiberdi.IController{
	//			&CatController{},
	//		},
	//		Injectables: []interface{}{
	//			&CatService{},
	//		},
	//	}
	//
	//	appModule := &fiberdi.Module{
	//		Modules: []fiberdi.IModule{
	//			catModule,
	//		},
	//	}
	Modules []IModule
}

Module manage your dependencies and routes

appModule := &fiberdi.Module{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL