我有一个将公开公开的 api 并有一个沙箱。我已经在我的 ResourceFactory 中编写了一些代码,所以 api.sandbox.whatever/whatever 会起作用,并且参数中的 sandbox=true 也会起作用,但这感觉就像一个巨大的黑客攻击。有什么更好的方法吗?
这是我的代码:
public class NinjectResourceFactory : IResourceFactory
{
private readonly IKernel _productionKernel;
private readonly IKernel _sandboxKernel;
public NinjectResourceFactory()
{
_productionKernel = new StandardKernel(new QueryMasterModule());
_sandboxKernel = new StandardKernel(new QueryMasterModule(true));
}
public object GetInstance(Type serviceType, InstanceContext instanceContext, HttpRequestMessage request)
{
string uri = request.RequestUri.ToString();
if (uri.Contains(".sandbox."))
{
return _sandboxKernel.Get(serviceType);
}
else if (uri.Contains("sandbox=true"))
{
request.RequestUri = new Uri(uri.Replace("sandbox=true", ""));
return _sandboxKernel.Get(serviceType);
}
else
{
return _productionKernel.Get(serviceType);
}
}
public void ReleaseInstance(InstanceContext instanceContext, object service)
{
// todo do I need to implement this?
}
}