Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Created September 5, 2016 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinyoo/dcf4189227700249064b682f0e3ebe21 to your computer and use it in GitHub Desktop.
Save justinyoo/dcf4189227700249064b682f0e3ebe21 to your computer and use it in GitHub Desktop.
Testing Azure Functions
public class ServiceLocator
{
private IDictionary<Type, object> _services;
public ServiceLocator()
{
this._services = new Dictionary<Type, object>();
}
public void AddService(Type type, object obj)
{
this._services.Add(type, obj);
}
public IMyServiceClass GetService()
{
if (!this._services.ContainsKey(typeof(IMyServiceClass)))
{
this._services.Add(typeof(IMyServiceClass), null);
}
var service = this._services[typeof(IMyServiceClass)] as IMyServiceClass;
if (service == null)
{
service = new MyServiceClass();
this._services[typeof(IMyServiceClass)] = service;
}
return service;
}
public MyStatusClass GetStatus()
{
if (!this._services.ContainsKey(typeof(MyStatusClass)))
{
this._services.Add(typeof(MyStatusClass), null);
}
var status = this._services[typeof(MyStatusClass)] as MyStatusClass;
if (status == null)
{
status = new MyStatusClass();
this._services[typeof(MyStatusClass)] = status;
}
return status;
}
}
public interface IMyServiceClass
{
void Process(HttpRequestMessage req);
}
public class MyServiceClass : IMyServiceClass
{
public void Process(HttpRequestMessage req)
{
return;
}
}
public class MyStatusClass
{
public string Status { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment