Skip to main content
added 123 characters in body
Source Link

I would like my project to adhere to the SOLID principles and write clean code, but I am still not very clear on when I should separate from the service layer.

I have a Web Api 2.0 Controller called ParkingController which has the following method:

public List<Week> GetParkingPlaces(DateTime date)
{
    date = DateTime.Now.ToWesternEuropeStandardTime().Date;
    return _service.GetWeeks(date);
}

And the service methods:

public List<Week> GetWeeks()
{
    // About 10 lines of logic here, calling CreateDaysInWeek and looping here
    return weeks;
}

private Week CreateDaysInWeek(DateTime startOfWeek, List<ParkingPlace> parkingPlaces)
{
    // About 10 lines of logic to Create days in week.
    return new Week(daysInWeek);
}

I separated the method GetWeeks into two methods, one being a private method to make my code cleaner and more understandable. Now when I see this private method I think hmm am I violating SRP?

My question is: Should I separate these functions into their own class like WeeksWithDaysCreator or even WeeksCreator calling DaysCreator? Or should I just leave this in the Service Class?

Edit: I want to know how much code I should put in my Service layer and when I should separate code into its own class.

I would like my project to adhere to the SOLID principles and write clean code, but I am still not very clear on when I should separate from the service layer.

I have a Web Api 2.0 Controller called ParkingController which has the following method:

public List<Week> GetParkingPlaces(DateTime date)
{
    date = DateTime.Now.ToWesternEuropeStandardTime().Date;
    return _service.GetWeeks(date);
}

And the service methods:

public List<Week> GetWeeks()
{
    // About 10 lines of logic here, calling CreateDaysInWeek and looping here
    return weeks;
}

private Week CreateDaysInWeek(DateTime startOfWeek, List<ParkingPlace> parkingPlaces)
{
    // About 10 lines of logic to Create days in week.
    return new Week(daysInWeek);
}

I separated the method GetWeeks into two methods, one being a private method to make my code cleaner and more understandable. Now when I see this private method I think hmm am I violating SRP?

My question is: Should I separate these functions into their own class like WeeksWithDaysCreator or even WeeksCreator calling DaysCreator? Or should I just leave this in the Service Class?

I would like my project to adhere to the SOLID principles and write clean code, but I am still not very clear on when I should separate from the service layer.

I have a Web Api 2.0 Controller called ParkingController which has the following method:

public List<Week> GetParkingPlaces(DateTime date)
{
    date = DateTime.Now.ToWesternEuropeStandardTime().Date;
    return _service.GetWeeks(date);
}

And the service methods:

public List<Week> GetWeeks()
{
    // About 10 lines of logic here, calling CreateDaysInWeek and looping here
    return weeks;
}

private Week CreateDaysInWeek(DateTime startOfWeek, List<ParkingPlace> parkingPlaces)
{
    // About 10 lines of logic to Create days in week.
    return new Week(daysInWeek);
}

I separated the method GetWeeks into two methods, one being a private method to make my code cleaner and more understandable. Now when I see this private method I think hmm am I violating SRP?

My question is: Should I separate these functions into their own class like WeeksWithDaysCreator or even WeeksCreator calling DaysCreator? Or should I just leave this in the Service Class?

Edit: I want to know how much code I should put in my Service layer and when I should separate code into its own class.

Source Link

Should I separate into own class when creating private methods in service layer?

I would like my project to adhere to the SOLID principles and write clean code, but I am still not very clear on when I should separate from the service layer.

I have a Web Api 2.0 Controller called ParkingController which has the following method:

public List<Week> GetParkingPlaces(DateTime date)
{
    date = DateTime.Now.ToWesternEuropeStandardTime().Date;
    return _service.GetWeeks(date);
}

And the service methods:

public List<Week> GetWeeks()
{
    // About 10 lines of logic here, calling CreateDaysInWeek and looping here
    return weeks;
}

private Week CreateDaysInWeek(DateTime startOfWeek, List<ParkingPlace> parkingPlaces)
{
    // About 10 lines of logic to Create days in week.
    return new Week(daysInWeek);
}

I separated the method GetWeeks into two methods, one being a private method to make my code cleaner and more understandable. Now when I see this private method I think hmm am I violating SRP?

My question is: Should I separate these functions into their own class like WeeksWithDaysCreator or even WeeksCreator calling DaysCreator? Or should I just leave this in the Service Class?