I have written a wrapper around the C# Facebook SDK usign the following code:
public interface IFacebookService
{
Uri GetLoginUri(string returnUrl);
FacebookResult OAuth(string url, string code);
void Post(string message, string accessToken);
}
The implementation looks like:
public class FacebookService : IFacebookService
{
public Uri GetLoginUri(string returnUrl)
{
var oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
// code removed for simplicity
return uri;
}
public FacebookResult OAuth(string url, string code)
{
FacebookOAuthResult oauthResult;
if (FacebookOAuthResult.TryParse(url, out oauthResult))
{
// code removed for simplicity
}
return result;
}
public void Post(string message, string accessToken)
{
var client = new FacebookClient(accessToken);
// code removed for simplicity
}
}
I use Ninject to inject this where needed to perform login using oauth and posting to the users Facebook wall.
I currently have this configured using:
kernel.Bind<IFacebookService>().To<FacebookService>().InSingletonScope();
Is it correct to use InSingletonScope? Since this is a third party library I am not sure if this is the right approach since all threads will share the instance.
I have no knowledge about the Facebook SDK. But as a general rule if the implementation is stateless then singleton is the correct scope. I assume this is the case with your implementation.