Skip to content

Questions about DI patterns #1125

Answered by Shane32
naratteu asked this question in Q&A
Discussion options

You must be logged in to vote

To understand better, take a look at the Message class. I'm going to add a Replies method for discussion purposes also.

public class Message
{
    [Id]
    public int Id { get; set; }

    [Name("Message")]
    public string Value { get; set; } = null!;

    public string From { get; set; } = null!;

    public DateTime Sent { get; set; }

    public IEnumerable<Message> Replies([FromServices] IChat chatService)
        => chatService.GetReplies(this);
}

What you will notice is that the Message class is a data model, not a service. It can contain service-like methods, but it's a data model with service methods layered on top. It would not make sense to have the Message class use DI to inj…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by naratteu
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants