Created
November 28, 2017 00:06
-
-
Save joelverhagen/f62c3761f8e06c2b54a8d91ca357f751 to your computer and use it in GitHub Desktop.
Example of custom IPackageService in NuGet.Server 2.8.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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