Skip to content

Instantly share code, notes, and snippets.

@joelverhagen
Created November 28, 2017 00:06
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 joelverhagen/f62c3761f8e06c2b54a8d91ca357f751 to your computer and use it in GitHub Desktop.
Save joelverhagen/f62c3761f8e06c2b54a8d91ca357f751 to your computer and use it in GitHub Desktop.
Example of custom IPackageService in NuGet.Server 2.8.2
using System.Data.Services;
using System.ServiceModel.Activation;
using System.Web;
using System.Web.Routing;
using NuGet.Server;
using NuGet.Server.DataServices;
using NuGet.Server.Infrastructure;
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(WebApplication1.NuGetRoutes), "Start")]
namespace WebApplication1
{
public static class NuGetRoutes {
public static void Start() {
MapRoutes(RouteTable.Routes);
NinjectBootstrapper.Kernel.Rebind<IPackageService>().To<ExamplePackageService>();
}
private static void MapRoutes(RouteCollection routes) {
// The default route is http://{root}/nuget/Packages
var factory = new DataServiceHostFactory();
var serviceRoute = new ServiceRoute("nuget", factory, typeof(Packages));
serviceRoute.Defaults = new RouteValueDictionary { { "serviceType", "odata" } };
serviceRoute.Constraints = new RouteValueDictionary { { "serviceType", "odata" } };
routes.Add("nuget", serviceRoute);
}
}
public class ExamplePackageService : IPackageService
{
private readonly PackageService _inner;
public ExamplePackageService(IServerPackageRepository repo, IPackageAuthenticationService auth)
{
_inner = new PackageService(repo, auth);
}
public void CreatePackage(HttpContextBase context)
{
_inner.CreatePackage(context);
}
public void DeletePackage(HttpContextBase context)
{
_inner.DeletePackage(context);
}
public void DownloadPackage(HttpContextBase context)
{
_inner.DownloadPackage(context);
}
public void PublishPackage(HttpContextBase context)
{
_inner.PublishPackage(context);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment