Commit 138f8a3d authored by Johannes Loher's avatar Johannes Loher
Browse files

refactor: Switch from configuration by annotations to using register

parent be59006d
Pipeline #120 passed with stages
in 1 minute and 38 seconds
......@@ -8,11 +8,11 @@ void main() @safe
import d_webservice_example.component_registration : registerComponents;
import d_webservice_example.controller.todo_controller : TodoController;
auto container = singleton();
auto container = singleton;
scope (exit)
container.terminate;
container.registerComponents();
container.registerComponents;
container.instantiate;
auto router = new URLRouter;
......@@ -22,5 +22,5 @@ void main() @safe
settings.bindAddresses = ["::", "0.0.0.0"];
listenHTTP(settings, router);
runApplication();
runApplication;
}
module d_webservice_example.business.todo_service;
import aermicioi.aedi : autowired, component;
import d_webservice_example.model.todo : Todo;
import std.uuid : UUID, randomUUID;
@component class TodoService
class TodoService
{
import d_webservice_example.data.todo_update_do : TodoUpdateDO;
......@@ -13,20 +12,20 @@ private:
public:
@autowired this(TodoRepository todoRepository) @safe
this(TodoRepository todoRepository) nothrow pure @nogc @safe
{
this.todoRepository = todoRepository;
}
Todo createTodo(Todo newTodo) @safe
{
immutable todo = Todo(newTodo.title, newTodo.content, randomUUID());
immutable todo = Todo(newTodo.title, newTodo.content, randomUUID);
return todoRepository.save(todo);
}
Todo[] getAllTodos() @safe
{
return todoRepository.findAll();
return todoRepository.findAll;
}
Todo getTodoByUuid(const UUID uuid) @safe
......
module d_webservice_example.component_registration;
import aermicioi.aedi : ConfigurableContainer, scan;
import aermicioi.aedi;
void registerComponents(ConfigurableContainer container) @safe
{
container.scan!(d_webservice_example.business.todo_service);
container.scan!(d_webservice_example.controller.todo_controller);
container.scan!(d_webservice_example.dataaccess.in_memory_todo_repository);
import d_webservice_example.business.todo_service : TodoRepository, TodoService;
import d_webservice_example.controller.todo_controller : TodoController;
import d_webservice_example.dataaccess.in_memory_todo_repository : InMemoryTodoRepository;
container.configure.register!(TodoRepository, InMemoryTodoRepository);
container.configure.register!TodoService.autowire;
container.configure.register!TodoController.autowire;
}
module d_webservice_example.controller.todo_controller;
import aermicioi.aedi : autowired, component;
import d_webservice_example.transport.todo_to : TodoTO;
import std.typecons : Nullable;
import std.uuid : UUID;
......@@ -25,7 +24,7 @@ interface TodoApi
void deleteTodo(UUID _uuid) @safe;
}
@component class TodoController : TodoApi
class TodoController : TodoApi
{
import d_webservice_example.business.todo_service : TodoService;
import d_webservice_example.mapper.todo_mapper : asTodoTO;
......@@ -35,7 +34,7 @@ private:
public:
@autowired this(TodoService todoService) @safe
this(TodoService todoService) nothrow pure @nogc @safe
{
this.todoService = todoService;
}
......@@ -53,7 +52,7 @@ public:
import std.algorithm.iteration : map;
import std.array : array;
return todoService.getAllTodos().map!asTodoTO.array;
return todoService.getAllTodos.map!asTodoTO.array;
}
override TodoTO getTodo(UUID _uuid) @safe
......
module d_webservice_example.dataaccess.in_memory_todo_repository;
import aermicioi.aedi : component, qualifier;
import d_webservice_example.business.todo_service : TodoRepository;
version (unittest)
......@@ -8,7 +7,7 @@ version (unittest)
import fluent.asserts;
}
@component @qualifier!TodoRepository() class InMemoryTodoRepository : TodoRepository
class InMemoryTodoRepository : TodoRepository
{
import d_webservice_example.model.todo : Todo;
import std.typecons : Nullable, nullable;
......
......@@ -5,6 +5,5 @@ import d_webservice_example.transport.todo_to : TodoTO;
TodoTO asTodoTO(Todo todo) nothrow pure @safe @nogc
{
return TodoTO(todo.uuid, todo.title, todo.content);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment