Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 865acc7

Browse files
committed
Addressed feedback from design meeting
1 parent 007556a commit 865acc7

File tree

21 files changed

+197
-517
lines changed

21 files changed

+197
-517
lines changed

src/Microsoft.AspNetCore.Mvc.Core/ApplicationParts/ApplicationPart.cs

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,8 @@
77

88
namespace Microsoft.AspNetCore.Mvc.ApplicationParts
99
{
10-
public class ApplicationPart : IEquatable<ApplicationPart>
10+
public abstract class ApplicationPart
1111
{
12-
private readonly IDictionary<Type, object> _features;
13-
14-
public ApplicationPart(Assembly assembly)
15-
{
16-
if (assembly == null)
17-
{
18-
throw new ArgumentNullException(nameof(assembly));
19-
}
20-
21-
_features = new Dictionary<Type, object>();
22-
Assembly = assembly;
23-
}
24-
25-
public Assembly Assembly { get; }
26-
27-
public T GetFeature<T>()
28-
{
29-
return _features.ContainsKey(typeof(T)) ? (T)_features[typeof(T)] : default(T);
30-
}
31-
32-
public void SetFeature<T>(T feature)
33-
{
34-
_features[typeof(T)] = feature;
35-
}
36-
37-
/// <inheritdoc />
38-
public bool Equals(ApplicationPart other)
39-
{
40-
return Assembly.Equals(other?.Assembly);
41-
}
42-
43-
/// <inheritdoc />
44-
public override bool Equals(object obj)
45-
{
46-
return obj is ApplicationPart && Equals((ApplicationPart)obj);
47-
}
48-
49-
/// <inheritdoc />
50-
public override int GetHashCode()
51-
{
52-
return Assembly.GetHashCode();
53-
}
12+
public abstract string Name { get; }
5413
}
5514
}

src/Microsoft.AspNetCore.Mvc.Core/ApplicationParts/ApplicationPartCollection.cs

Lines changed: 0 additions & 85 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc.ApplicationParts;
6+
7+
namespace Microsoft.AspNetCore.Mvc.ApplicationParts
8+
{
9+
public class ApplicationPartManager
10+
{
11+
public IList<IApplicationFeatureProvider> Providers { get; } =
12+
new List<IApplicationFeatureProvider>();
13+
14+
public IList<ApplicationPart> ApplicationParts { get; } =
15+
new List<ApplicationPart>();
16+
17+
public void PopulateFeature<T>(T feature)
18+
{
19+
if (feature == null)
20+
{
21+
throw new ArgumentNullException(nameof(feature));
22+
}
23+
24+
foreach (var provider in Providers.OfType<IApplicationFeatureProvider<T>>())
25+
{
26+
provider.GetFeature(ApplicationParts, feature);
27+
}
28+
}
29+
}
30+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Threading.Tasks;
6+
7+
namespace Microsoft.AspNetCore.Mvc.ApplicationParts
8+
{
9+
public class AssemblyPart : ApplicationPart, IExportTypes
10+
{
11+
private readonly Assembly _assembly;
12+
13+
public AssemblyPart(Assembly assembly)
14+
{
15+
if (assembly == null)
16+
{
17+
throw new ArgumentNullException(nameof(assembly));
18+
}
19+
20+
_assembly = assembly;
21+
}
22+
23+
public override string Name => _assembly.GetName().Name;
24+
25+
public IEnumerable<TypeInfo> Types => _assembly.DefinedTypes;
26+
}
27+
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
2-
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3-
4-
using System.Reflection;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
55

66
namespace Microsoft.AspNetCore.Mvc.ApplicationParts
77
{
8-
public interface IApplicationFeatureProvider<T>
8+
public interface IApplicationFeatureProvider
99
{
10-
T GetFeature(Assembly assembly);
1110
}
12-
}
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Collections;
5+
using System.Collections.Generic;
6+
using System.Reflection;
7+
8+
namespace Microsoft.AspNetCore.Mvc.ApplicationParts
9+
{
10+
public interface IApplicationFeatureProvider<T> : IApplicationFeatureProvider
11+
{
12+
void GetFeature(IEnumerable<ApplicationPart> parts, T feature);
13+
}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Threading.Tasks;
6+
7+
namespace Microsoft.AspNetCore.Mvc.ApplicationParts
8+
{
9+
public interface IExportTypes
10+
{
11+
IEnumerable<TypeInfo> Types { get; }
12+
}
13+
}

src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/IMvcBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public interface IMvcBuilder
1818
/// <summary>
1919
/// Gets a list of <see cref="ApplicationPart"/> instances that compose the application.
2020
/// </summary>
21-
ApplicationPartCollection ApplicationParts { get; }
21+
ApplicationPartManager Manager { get; }
2222
}
2323
}

src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/IMvcCoreBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public interface IMvcCoreBuilder
1818
/// <summary>
1919
/// Gets a list of <see cref="ApplicationPart"/> instances that compose the application.
2020
/// </summary>
21-
ApplicationPartCollection ApplicationParts { get; }
21+
ApplicationPartManager Manager { get; }
2222
}
2323
}

src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ public static IMvcCoreBuilder AddMvcCore(this IServiceCollection services)
4242
throw new ArgumentNullException(nameof(services));
4343
}
4444

45-
var collection = GetApplicationPartCollection(services);
46-
services.TryAddSingleton(collection);
45+
var partManager = GetApplicationPartManager(services);
46+
services.TryAddSingleton(partManager);
4747

4848
ConfigureDefaultServices(services);
4949
AddMvcCoreServices(services);
5050

51-
var builder = new MvcCoreBuilder(services, collection);
51+
var builder = new MvcCoreBuilder(services, partManager);
5252

5353
return builder;
5454
}
5555

56-
private static ApplicationPartCollection GetApplicationPartCollection(IServiceCollection services)
56+
private static ApplicationPartManager GetApplicationPartManager(IServiceCollection services)
5757
{
58-
var collection = GetServiceFromCollection<ApplicationPartCollection>(services);
59-
if (collection == null)
58+
var manager = GetServiceFromCollection<ApplicationPartManager>(services);
59+
if (manager == null)
6060
{
6161
var environment = GetServiceFromCollection<IHostingEnvironment>(services);
6262
if (environment == null)
@@ -69,15 +69,15 @@ private static ApplicationPartCollection GetApplicationPartCollection(IServiceCo
6969
}
7070

7171
var assemblies = new DefaultAssemblyProvider(environment).CandidateAssemblies;
72-
collection = new ApplicationPartCollection();
72+
manager = new ApplicationPartManager();
7373

7474
foreach (var assembly in assemblies)
7575
{
76-
collection.Register(assembly);
76+
manager.ApplicationParts.Add(new AssemblyPart(assembly));
7777
}
7878
}
7979

80-
return collection;
80+
return manager;
8181
}
8282

8383
private static T GetServiceFromCollection<T>(IServiceCollection services)

0 commit comments

Comments
 (0)