I have class structured as the following:
public interface IFooService {
void DoStuff1();
void DoStuff2();
}
public class FooService: IFooService {
private string _data;
public static FooService CreateDefault() {
var ret = new FooService {
_data = "Default Data"
};
return ret;
}
public static FooService CreateFromFile(string path) {
string data = File.ReadAllText(path);
var ret = new FooService {
_data = data
};
return ret;
}
public static FooService CreateFromValue(string data) {
var ret = new FooService {
_data = data
};
return ret;
}
public void DoStuff1() {
//
}
public void DoStuff2() {
//
}
}
Usually, I would do the following in ConfigureServices:
services.AddSingleton<IFooService, FooService>();
But in this case, how do I call a specific factory method?
It's better to create a factory class to handle the object instantiation?
It's there a better way to structure the code?