Should I use static in the following 2 cases:
Case 1)
public class RequestHeader { private string Username { get; set; } private string Password { get; set; } private string AccessKey { get; set; } public string url { get; set; } public string pageid { get; set; } public string organizationid { get; set; } private RequestHeader() { } public static RequestHeader GetRequestHeader(string url, string pageid, string organizationid) { return new RequestHeader() { Username = "Some logic to fetch username", Password = "Some logic to fetch password", AccessKey = "Some access key", url = url, pageid = pageid, organizationid = organizationid, }; } } Case 2)
public class HttpClientHelper { public static HttpClient GetHttpClient(RequestHeader header) { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); foreach (var property in header.GetType().GetProperties()) { client.DefaultRequestHeaders.Add(property.Name, property.GetValue(header).ToString()); } return client; } } I know that static is not used where state is maintained. I believe I am not maintaining any state here. I will be using this in a class library and I will be using these for calling a rest service.
The only thing which makes me want to use static here is not to initialize these class.(I know this is a very baaad reason).
Please let me know your thoughts. Is there something which I am not seeing in this.
Note: 1) I am aware of the small casing for some of the properties. It is in sync with the rest service on which I have absolutely no control. 2) If I have multiple RequestHeader in future, I might create an IRequestHeader which has a method GetRequestHeader. So the different RequestHeaders will implement this. In this case I know I cant keep a static method in interface. Please Keep these 2 conditions away and let me know your thoughts.