Skip to content

Class TodoService

Namespace: MyApp.Application
Assembly: MyApp.Application.dll

Use-case service for todo items: the only surface the API layer talks to.

public sealed class TodoService

Inheritance

object ← TodoService

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks

The service depends on the domain repository contract () and never exposes domain entities to callers; everything crosses the boundary as .

Constructors

TodoService(ITodoRepository)

Initializes a new instance of the class.

public TodoService(ITodoRepository repository)

Parameters

repository ITodoRepository

The backing todo repository.

Methods

Create(CreateTodoRequest)

Creates a new todo item from the given request.

public TodoDto Create(CreateTodoRequest request)

Parameters

request CreateTodoRequest

The creation request.

Returns

TodoDto

The created item as a .

Exceptions

ArgumentException

Thrown when the request title is empty.

Delete(Guid)

Deletes a todo item.

public bool Delete(Guid id)

Parameters

id Guid

The identifier of the item.

Returns

bool

true when the item was deleted; otherwise false.

Get(Guid)

Returns a single todo item.

public TodoDto? Get(Guid id)

Parameters

id Guid

The identifier to look up.

Returns

TodoDto?

The matching DTO, or null when not found.

GetAll()

Returns all todo items, newest last.

public IReadOnlyList<TodoDto> GetAll()

Returns

IReadOnlyList<TodoDto>

Every stored item as a .

SetCompletion(Guid, bool)

Sets the completion state of a stored todo item.

public TodoDto? SetCompletion(Guid id, bool isCompleted)

Parameters

id Guid

The identifier of the item.

isCompleted bool

The new completion state.

Returns

TodoDto?

The updated DTO, or null when the item does not exist.