Y
Y a h y a
Guest
Hi
In my single project I have an API Wrapper class as below which in turn allows access to various services which get data from remote API;
class APIWrapper
{
var baseUrl = "https://blah-blah/";
AuthenticationService authenticationService = new AuthenticationService(baseUrl);
BookedJobService bookedService = new BookedJobService(baseUrl);
DocumentService documentService = new DocumentService(baseUrl);
NotificationService notificationService = new NotificationService(baseUrl);
// etc.
}
My issue is how do I access the initialised API Wrapper class from other classes in the project? After initialising API Wrapper do I setup a public reference to it which I can access everywhere in my project or do I (God forbid) initialise it every time? At present I am handling it as below ie I save the reference to initialised API Wrapper using static value.
class ApplicationSettings
{
private static ApplicationSettings _instance;
public APIWrapper apiwrapper { get; set; }
public static ApplicationSettings Instance()
{
if (_instance is null)
{
_instance = new ApplicationSettings();
}
return _instance;
}
protected ApplicationSettings()
{
}
}
Is this the right way to do it or have I missed something?
Thanks
Regards
Continue reading...
In my single project I have an API Wrapper class as below which in turn allows access to various services which get data from remote API;
class APIWrapper
{
var baseUrl = "https://blah-blah/";
AuthenticationService authenticationService = new AuthenticationService(baseUrl);
BookedJobService bookedService = new BookedJobService(baseUrl);
DocumentService documentService = new DocumentService(baseUrl);
NotificationService notificationService = new NotificationService(baseUrl);
// etc.
}
My issue is how do I access the initialised API Wrapper class from other classes in the project? After initialising API Wrapper do I setup a public reference to it which I can access everywhere in my project or do I (God forbid) initialise it every time? At present I am handling it as below ie I save the reference to initialised API Wrapper using static value.
class ApplicationSettings
{
private static ApplicationSettings _instance;
public APIWrapper apiwrapper { get; set; }
public static ApplicationSettings Instance()
{
if (_instance is null)
{
_instance = new ApplicationSettings();
}
return _instance;
}
protected ApplicationSettings()
{
}
}
Is this the right way to do it or have I missed something?
Thanks
Regards
Continue reading...