There is a dynamic service setup after the static functor service setup. The API should be more modular and more ergonomic.
API
This is how the usage should look like:
module Service = struct
module Database = Sihl.Data.Db.Service.Default
module MigrationRepo = Sihl.Data.Migration.Service.Repo.MakeMariaDb (Database)
module Migration = Sihl.Data.Migration.Service.Make (Database) (MigrationRepo)
module WebServer = Sihl.Web.Server.Service.Opium
module Schedule = Sihl.Schedule.Service.Default
end
let middlewares = [...]
let jobs = [...]
let schedules = [...]
let email_config = [("SMTP_PORT", "..."); ("SMTP_USER", "...")]
let commands = [...]
(* Some global configuration *)
let configuration = [...]
(* Custom log reporter streaming to logstash *)
let reporter = ....
(* Domain services *)
let pizza_delivery_service = Pizza_delivery.Service.configure [("DEFAULT_PIZZA": "margherita")]
let services = [
Service.Log.configure ~reporter [("LOG_LEVEL", "debug")];
Service.User.configure [];
Service.Database.configure [("DATABASE_URL", "...")];
Service.WebServer.configure
~middlewares
(* Register own service so it will be started when starting the web server *)
~dependencies:[ pizza_delivery_service ]
[("PORT", "3000"), ("MAX_BODY_SIZE", "10MB")];
Service.Queue.configure ~jobs [];
Service.Scheduler.configure ~schedules [];
Service.Email.configure email_config;
]
let () = Sihl.App.start ~commands ~configuration services
This API has several implications:
The core needs to know about commands, basic logging and service configurations
The configuration is not statically typed. We want to run validations that can not be expressed easily with static types. This will lead to startup checking, so the system will not even start with wrong configurations.
Todo
Learn how to use cmdliner and implement core/command.ml
Implement a configuration module to merge .env with env vars and run conformist on startup to get the statically typed validated configuration
Implement configure in services where first argument is configuration and the second argument is setup data that is optional
Goal
There is a dynamic service setup after the static functor service setup. The API should be more modular and more ergonomic.
API
This is how the usage should look like:
This API has several implications:
Todo
core/command.ml
.env
with env vars and run conformist on startup to get the statically typed validated configurationconfigure
in services where first argument is configuration and the second argument is setup data that is optional