Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 8a9c8aa

Browse files
authored
Merge pull request #1370 from github/fixes/1368-simplify-ViewViewModelFactory
Simplify ViewViewModelFactory
2 parents 6359067 + 5fbef64 commit 8a9c8aa

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/GitHub.App/Factories/ViewViewModelFactory.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ public class ViewViewModelFactory : IViewViewModelFactory
2020

2121
[ImportingConstructor]
2222
public ViewViewModelFactory(
23-
IGitHubServiceProvider serviceProvider,
24-
ICompositionService cc)
23+
IGitHubServiceProvider serviceProvider)
2524
{
2625
this.serviceProvider = serviceProvider;
27-
cc.SatisfyImportsOnce(this);
2826
}
2927

30-
[ImportMany(AllowRecomposition = true)]
28+
[ImportMany]
3129
IEnumerable<ExportFactory<FrameworkElement, IViewModelMetadata>> Views { get; set; }
3230

3331
/// <inheritdoc/>
@@ -45,7 +43,7 @@ public FrameworkElement CreateView<TViewModel>() where TViewModel : IViewModel
4543
/// <inheritdoc/>
4644
public FrameworkElement CreateView(Type viewModel)
4745
{
48-
var f = Views.FirstOrDefault(x => x.Metadata.ViewModelType.Contains(viewModel));
46+
var f = Views.FirstOrDefault(x => x.Metadata.ViewModelType.Contains(viewModel.FullName));
4947
return f?.CreateExport().Value;
5048
}
5149
}

src/GitHub.Exports/Exports/ExportMetadata.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ public enum LinkType
3232
/// </summary>
3333
[MetadataAttribute]
3434
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
35+
[SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments",
36+
Justification = "Store string rather than Type as metadata")]
3537
public sealed class ExportViewForAttribute : ExportAttribute
3638
{
3739
public ExportViewForAttribute(Type viewModelType)
3840
: base(typeof(FrameworkElement))
3941
{
40-
ViewModelType = viewModelType;
42+
ViewModelType = viewModelType.FullName;
4143
}
4244

43-
public Type ViewModelType { get; }
45+
public string ViewModelType { get; }
4446
}
4547

4648
/// <summary>
@@ -69,7 +71,7 @@ public ExportMenuAttribute() : base(typeof(IMenuHandler))
6971
public interface IViewModelMetadata
7072
{
7173
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
72-
Type[] ViewModelType { get; }
74+
string[] ViewModelType { get; }
7375
}
7476

7577
/// <summary>

0 commit comments

Comments
 (0)