c # – Dependency injection in constructor vs Supply argument in utility functions

I have the following:

Public class Person {
public string FirstName {get; set;} = "";
public string MiddleName {get; set;} = "";
public string LastName {get; set;} = "";
public string Title {get; set;} = "";
}

public class program
{
public static void Main ()
{
var person = new Person {FirstName = "Daniel", MiddleName = "W", Name = "Craig", Title = "Mr"};
}
}

I write a class of service that reports to a user

  • Full name (First name + First name + Last name)
  • Title + Full name
  • First and last name

By using the addictive injection, I have the following elements:

(1)

Public class NameService {

private read-only Person _person;
NameService public (person person) {
_person = person;
}

public string GetFullName () {
var fullName = $ "{_ person.FirstName} {_person.MiddleName} {_person.LastName}";

return FullName;
}

public string GetFullNameWithTitle () {
var fullNameWithTitle = $ "{_ person.Title} {_person.FirstName} {_person.MiddleName} {_person.LastName}";

return fullNameWithTitle;
}

public string GetFirstLastName () {
var fullName = $ "{_ person.FirstName} {_person.LastName}";

return FullName;
}
}

Which I can use like this:

var person = new Person {FirstName = "Daniel", MiddleName = "W", Name = "Craig", Title = "Mr"};
var service = new NameService (person);

var fullName = service.GetFullName ();

however, I can also define the service like this:

(2)

Public class NameService
{
public NameService () {}

public channel GetFullName (person person)
{
var fullName = $ "{person.FirstName} {person.MiddleName} {person.LastName}";
return FullName;
}

public channel GetFullNameWithTitle (Person person)
{
var fullNameWithTitle = $ "{person.Title} {person.FirstName} {person.MiddleName} {person.LastName}";
return fullNameWithTitle;
}

public channel GetFirstLastName (Person Person)
{
var fullName = $ "{person.FirstName} {person.LastName}";
return FullName;
}
}

And then get the full name of a person as follows:

                var person = new Person {FirstName = "Daniel", MiddleName = "W", Name = "Craig", Title = "Mr"};
var service = new NameService ();

var fullName = service.GetFullName (person);

What is the best approach? My minds:

(1)

Looks like the service is designed on a "per person" basis. This means that the call of the full name of another person will require the instantiation of a new service with a new Person argument (and this does not matter).

(2)

It is a lightweight constructor that allows different Person objects to be provided to GetFullName (person) to allow different renderings of the full name.

What other advantages and disadvantages can you think of?