-
Notifications
You must be signed in to change notification settings - Fork 643
/
NuGetViewBase.cs
96 lines (77 loc) · 2.82 KB
/
NuGetViewBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using NuGet.Services.Entities;
using NuGetGallery.Configuration;
namespace NuGetGallery.Views
{
public abstract class NuGetViewBase : WebViewPage
{
private readonly Lazy<NuGetContext> _nugetContext;
public NuGetContext NuGetContext
{
get { return _nugetContext.Value; }
}
public IGalleryConfigurationService Config
{
get { return NuGetContext.Config; }
}
public User CurrentUser
{
get { return NuGetContext.CurrentUser; }
}
public Lazy<IContentObjectService> ContentObjectService => new Lazy<IContentObjectService>(() => DependencyResolver.Current.GetService<IContentObjectService>());
public bool ShowAuthInHeader => true;
protected NuGetViewBase()
{
_nugetContext = new Lazy<NuGetContext>(GetNuGetContextThunk(this));
}
internal static Func<NuGetContext> GetNuGetContextThunk(WebViewPage self)
{
return () =>
{
var ctrl = self.ViewContext.Controller as AppController;
if (ctrl == null)
{
throw new InvalidOperationException("NuGetViewBase should only be used on views for actions on AppControllers");
}
return ctrl.NuGetContext;
};
}
protected override void InitializePage()
{
base.InitializePage();
ViewBag.Sections = new Lazy<List<string>>(() => new List<string>());
}
}
public abstract class NuGetViewBase<T> : WebViewPage<T>
{
private readonly Lazy<NuGetContext> _nugetContext;
public NuGetContext NuGetContext
{
get { return _nugetContext.Value; }
}
public IGalleryConfigurationService Config
{
get { return NuGetContext.Config; }
}
public User CurrentUser
{
get { return NuGetContext.CurrentUser; }
}
public Lazy<IContentObjectService> ContentObjectService => new Lazy<IContentObjectService>(() => DependencyResolver.Current.GetService<IContentObjectService>());
public bool ShowAuthInHeader => true;
public bool LinkOpenSearchXml => true;
protected NuGetViewBase()
{
_nugetContext = new Lazy<NuGetContext>(NuGetViewBase.GetNuGetContextThunk(this));
}
protected override void InitializePage()
{
base.InitializePage();
ViewBag.Sections = new Lazy<List<string>>(() => new List<string>());
}
}
}