I was basically playing with WPF before and just started with Blazor. Can somebody help me to clear some basic "clean code" topics to understand how to proceed.
First initialization: I would like to initialize variables. How I should do it? From Constructor or OnInitializedAsync or OnInitialized or some other way?
I mean in constructor:
private IEnumerable<Customer> CustomerList { get; set; }
public Projects()
{
this.CustomerList = List<Customer>();
this.ProjectModel.ProjectStartDate = DateTime.Today;
this.ProjectModel.ProjectEndDate = DateTime.Today;
}
OnInitializedAsync or OnInitialized:
private IEnumerable<Customer> CustomerList { get; set; }
protected async override Task OnInitializedAsync()
{
this.CustomerList = List<Customer>();
this.ProjectModel.ProjectStartDate = DateTime.Today;
this.ProjectModel.ProjectEndDate = DateTime.Today;
}
Yet another way (However I personally prefer to have them all in one place):
private IEnumerable<Customer> CustomerList { get; set; } = List<Customer>();
I have noticed that constructor way does not work and only after moving these into OnInitializedAsync or OnInitialized actually works. Why so?
Second: variables.
I can define this way:
private string projectManager;
private IEnumerable<Customer> customerList;
and this:
private IEnumerable<Customer> CustomerList { get; set; }
private string ProjectManager { get; set; }
Which one is correct? What is the difference?