Skip to content

Commit 89329d7

Browse files
TEMP: possibly split to first take the changes in the various unit tests and then the removal of ContextAwareTypeUtility
1 parent 8f40b57 commit 89329d7

File tree

30 files changed

+208
-448
lines changed

30 files changed

+208
-448
lines changed

Remotion/Core/Core/Configuration/TypeDiscovery/TypeDiscoveryConfiguration.cs

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -70,74 +70,13 @@ public TypeDiscoveryConfiguration ()
7070
}
7171

7272
/// <summary>
73-
/// Gets or sets the <see cref="TypeDiscoveryMode"/> to be used for type discovery.
74-
/// </summary>
75-
/// <value>The <see cref="TypeDiscoveryMode"/> to be used for type discovery.</value>
76-
[ConfigurationProperty("mode", DefaultValue = TypeDiscoveryMode.Automatic, IsRequired = false)]
77-
public TypeDiscoveryMode Mode
78-
{
79-
get { return (TypeDiscoveryMode)this["mode"]; }
80-
set { this["mode"] = value; }
81-
}
82-
83-
/// <summary>
84-
/// Gets a <see cref="RootAssembliesElement"/> describing specific root assemblies to be used. This is only relevant
85-
/// if <see cref="Mode"/> is set to <see cref="TypeDiscoveryMode.SpecificRootAssemblies"/>. In this mode, an
86-
/// <see cref="AssemblyFinderTypeDiscoveryService"/> is created, and the given root assemblies are employed for type discovery.
87-
/// Note that even if an assembly is specified as a root assembly, the default filtering rules (<see cref="ApplicationAssemblyLoaderFilter"/>)
88-
/// still apply even for that assembly.
73+
/// Gets a <see cref="RootAssembliesElement"/> describing specific root assemblies to be used.
8974
/// </summary>
9075
/// <value>A <see cref="RootAssembliesElement"/> describing specific root assemblies to be used.</value>
9176
[ConfigurationProperty("specificRootAssemblies", IsRequired = false)]
9277
public RootAssembliesElement SpecificRootAssemblies
9378
{
9479
get { return (RootAssembliesElement)this["specificRootAssemblies"]; }
9580
}
96-
97-
/// <summary>
98-
/// Creates an <see cref="ITypeDiscoveryService"/> instance as indicated by <see cref="Mode"/>.
99-
/// </summary>
100-
/// <returns>A new <see cref="ITypeDiscoveryService"/> that discovers types as indicated by <see cref="Mode"/>.</returns>
101-
public ITypeDiscoveryService CreateTypeDiscoveryService ()
102-
{
103-
switch (Mode)
104-
{
105-
case TypeDiscoveryMode.SpecificRootAssemblies:
106-
return CreateServiceWithSpecificRootAssemblies();
107-
default:
108-
return CreateServiceWithAutomaticDiscovery();
109-
}
110-
}
111-
112-
private ITypeDiscoveryService CreateServiceWithSpecificRootAssemblies ()
113-
{
114-
var assemblyLoader = CreateAllAssemblyLoader();
115-
var rootAssemblyFinder = SpecificRootAssemblies.CreateRootAssemblyFinder(assemblyLoader);
116-
return CreateServiceWithAssemblyFinder(rootAssemblyFinder);
117-
}
118-
119-
private ITypeDiscoveryService CreateServiceWithAutomaticDiscovery ()
120-
{
121-
var assemblyLoader = CreateApplicationAssemblyLoader();
122-
var searchPathRootAssemblyFinder = SearchPathRootAssemblyFinder.CreateForCurrentAppDomain(false, assemblyLoader);
123-
return CreateServiceWithAssemblyFinder(searchPathRootAssemblyFinder);
124-
}
125-
126-
private ITypeDiscoveryService CreateServiceWithAssemblyFinder (IRootAssemblyFinder customRootAssemblyFinder)
127-
{
128-
var filteringAssemblyLoader = CreateApplicationAssemblyLoader();
129-
var assemblyFinder = new CachingAssemblyFinderDecorator(new AssemblyFinder(customRootAssemblyFinder, filteringAssemblyLoader));
130-
return new AssemblyFinderTypeDiscoveryService(assemblyFinder);
131-
}
132-
133-
private IAssemblyLoader CreateApplicationAssemblyLoader ()
134-
{
135-
return new FilteringAssemblyLoader(ApplicationAssemblyLoaderFilter.Instance);
136-
}
137-
138-
private IAssemblyLoader CreateAllAssemblyLoader ()
139-
{
140-
return new FilteringAssemblyLoader(new LoadAllAssemblyLoaderFilter());
141-
}
14281
}
14382
}

Remotion/Core/Core/Reflection/ContextAwareTypeUtility.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
//
1717
using System;
1818
using System.ComponentModel.Design;
19-
using System.Threading;
20-
using Remotion.Configuration.TypeDiscovery;
2119
using Remotion.ServiceLocation;
2220

2321
namespace Remotion.Reflection
@@ -29,28 +27,15 @@ namespace Remotion.Reflection
2927
/// <threadsafety static="true" instance="false"/>
3028
public static class ContextAwareTypeUtility
3129
{
32-
/// <summary>Workaround to allow reflection to reset the fields since setting a static readonly field is not supported in .NET 3.0 and later.</summary>
33-
private class Fields
34-
{
35-
public readonly Lazy<ITypeDiscoveryService> DefaultTypeDiscoveryService =
36-
new Lazy<ITypeDiscoveryService>(
37-
() => TypeDiscoveryConfiguration.Current.CreateTypeDiscoveryService(),
38-
LazyThreadSafetyMode.ExecutionAndPublication);
39-
}
40-
41-
private static readonly Fields s_fields = new Fields();
42-
4330
/// <summary>
44-
/// Gets the current context-specific <see cref="ITypeDiscoveryService"/>. If an <see cref="T:System.ComponentModel.Design.IDesignerHost"/> is available,
45-
/// the designer's <see cref="ITypeDiscoveryService"/> is returned. Otherwise, the <see cref="T:Remotion.Configuration.TypeDiscovery.TypeDiscoveryConfiguration"/>
46-
/// is used to create a new <see cref="ITypeDiscoveryService"/> when the property is first retrieved. That instance is stored for later uses.
31+
/// Gets the current context-specific <see cref="ITypeDiscoveryService"/>.
4732
/// </summary>
48-
/// <returns>The current context-specific <see cref="ITypeDiscoveryService"/>.</returns>
33+
[Obsolete("Retrieve via the application's IoC container, e.g. SafeServiceLocator.Current.GetInstance<ITypeDiscoveryService>(). (Version 6.0.0)")]
4934
public static ITypeDiscoveryService GetTypeDiscoveryService ()
5035
{
5136
// Here you could choose to get the ITypeDiscoveryService from IDesignerHost.GetService (typeof (ITypeDiscoveryService)) instead of the resolved one.
5237

53-
return s_fields.DefaultTypeDiscoveryService.Value;
38+
return SafeServiceLocator.Current.GetInstance<ITypeDiscoveryService>();
5439
}
5540

5641
/// <summary>

Remotion/Core/Core/Schemas/TypeDiscoveryConfiguration.xsd

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@
4444
</xs:complexType>
4545
</xs:element>
4646
</xs:choice>
47-
48-
<xs:attribute name="mode" default="Automatic" use="optional">
49-
<xs:simpleType>
50-
<xs:restriction base="xs:string">
51-
<xs:enumeration value="Automatic"/>
52-
<xs:enumeration value="SpecificRootAssemblies"/>
53-
</xs:restriction>
54-
</xs:simpleType>
55-
</xs:attribute>
5647
</xs:complexType>
5748
</xs:element>
5849

Remotion/Core/Core/ServiceLocation/BootstrapServiceConfigurationExtensions.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
// along with re-motion; if not, see http://www.gnu.org/licenses.
1616
//
1717
using System;
18+
using Remotion.Configuration.TypeDiscovery;
19+
using Remotion.Reflection.TypeDiscovery.AssemblyFinding;
20+
using Remotion.Reflection.TypeDiscovery.AssemblyLoading;
1821
using Remotion.Utilities;
1922

2023
namespace Remotion.ServiceLocation
@@ -63,5 +66,22 @@ public static void Register<TService> (this IBootstrapServiceConfiguration boots
6366
typeof(TService),
6467
ServiceImplementationInfo.CreateSingle(() => instance, LifetimeKind.Singleton)));
6568
}
69+
70+
/// <summary>
71+
/// The given root assemblies are employed for type discovery.
72+
/// </summary>
73+
/// <param name="bootstrapServiceConfiguration"></param>
74+
public static void RegisterSpecificRootAssemblies (this IBootstrapServiceConfiguration bootstrapServiceConfiguration)
75+
{
76+
ArgumentUtility.CheckNotNull("bootstrapServiceConfiguration", bootstrapServiceConfiguration);
77+
78+
var assemblyLoader = new FilteringAssemblyLoader(new LoadAllAssemblyLoaderFilter());
79+
var specificRootAssemblies = TypeDiscoveryConfiguration.Current.SpecificRootAssemblies;
80+
var namedFinder = specificRootAssemblies.ByName.CreateRootAssemblyFinder(assemblyLoader);
81+
var filePatternFinder = specificRootAssemblies.ByFile.CreateRootAssemblyFinder(assemblyLoader);
82+
var rootAssemblyFinder = new CompositeRootAssemblyFinder(new IRootAssemblyFinder[] { namedFinder, filePatternFinder });
83+
84+
bootstrapServiceConfiguration.Register<IRootAssemblyFinder>(rootAssemblyFinder);
85+
}
6686
}
6787
}

Remotion/Core/Core/ServiceLocation/DefaultServiceLocator.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
//
1717
using System;
1818
using System.Collections.Generic;
19+
using System.ComponentModel.Design;
1920
using System.Linq;
20-
using Remotion.Logging;
2121
using Remotion.Reflection;
22-
using Remotion.Reflection.TypeDiscovery;
2322
using Remotion.Utilities;
2423

2524
namespace Remotion.ServiceLocation
@@ -68,9 +67,13 @@ public sealed partial class DefaultServiceLocator : IServiceLocator
6867

6968
public static DefaultServiceLocator CreateWithBootstrappedServices ()
7069
{
71-
var defaultServiceLocator = new DefaultServiceLocator(new DefaultServiceConfigurationDiscoveryService(ContextAwareTypeUtility.GetTypeDiscoveryService()));
72-
7370
var bootstrapServiceLocatorEntries = SafeServiceLocator.BootstrapConfiguration.GetRegistrations();
71+
72+
var provider = new DefaultServiceLocatorProvider(new BootstrapServiceConfigurationDiscoveryService());
73+
var bootstrapServiceLocator = provider.GetServiceLocator(bootstrapServiceLocatorEntries);
74+
var typeDiscoveryService = bootstrapServiceLocator.GetInstance<ITypeDiscoveryService>();
75+
76+
var defaultServiceLocator = new DefaultServiceLocator(new DefaultServiceConfigurationDiscoveryService(typeDiscoveryService));
7477
foreach (var serviceConfigurationEntry in bootstrapServiceLocatorEntries)
7578
defaultServiceLocator.Register(serviceConfigurationEntry);
7679

Remotion/Core/ExtensibleEnums.UnitTests/Infrastructure/ExtensibleEnumDefinitionCacheTest.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
// along with re-motion; if not, see http://www.gnu.org/licenses.
1616
//
1717
using System;
18+
using System.ComponentModel.Design;
1819
using NUnit.Framework;
1920
using Remotion.Development.NUnit.UnitTesting;
2021
using Remotion.Development.UnitTesting;
2122
using Remotion.ExtensibleEnums.Infrastructure;
2223
using Remotion.ExtensibleEnums.UnitTests.TestDomain;
23-
using Remotion.Reflection;
2424
using Remotion.ServiceLocation;
2525

2626
namespace Remotion.ExtensibleEnums.UnitTests.Infrastructure
@@ -30,12 +30,15 @@ public class ExtensibleEnumDefinitionCacheTest
3030
{
3131
private ExtensibleEnumDefinitionCache _cache;
3232
private DefaultServiceLocator _serviceLocator;
33+
private ITypeDiscoveryService _typeDiscoveryService;
3334

3435
[SetUp]
3536
public void SetUp ()
3637
{
3738
_serviceLocator = DefaultServiceLocator.CreateWithBootstrappedServices();
38-
_cache = new ExtensibleEnumDefinitionCache(new ExtensibleEnumValueDiscoveryService());
39+
_typeDiscoveryService = _serviceLocator.GetInstance<ITypeDiscoveryService>();
40+
41+
_cache = new ExtensibleEnumDefinitionCache(new ExtensibleEnumValueDiscoveryService(_typeDiscoveryService));
3942
}
4043

4144
[Test]
@@ -44,7 +47,7 @@ public void Initialization ()
4447
Assert.That(_cache.ValueDiscoveryService, Is.InstanceOf(typeof(ExtensibleEnumValueDiscoveryService)));
4548
Assert.That(
4649
((ExtensibleEnumValueDiscoveryService)_cache.ValueDiscoveryService).TypeDiscoveryService,
47-
Is.SameAs(ContextAwareTypeUtility.GetTypeDiscoveryService()));
50+
Is.SameAs(_typeDiscoveryService));
4851
}
4952

5053
[Test]

Remotion/Core/ExtensibleEnums/Infrastructure/ExtensibleEnumValueDiscoveryService.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ public class ExtensibleEnumValueDiscoveryService : IExtensibleEnumValueDiscovery
3838

3939
private readonly bool _excludeGlobalTypes = !AssemblyTypeCache.IsGacAssembly(typeof(ExtensibleEnum<>).Assembly);
4040

41-
public ExtensibleEnumValueDiscoveryService ()
42-
{
43-
_typeDiscoveryService = ContextAwareTypeUtility.GetTypeDiscoveryService();
44-
}
45-
46-
protected ExtensibleEnumValueDiscoveryService (ITypeDiscoveryService typeDiscoveryService)
41+
public ExtensibleEnumValueDiscoveryService (ITypeDiscoveryService typeDiscoveryService)
4742
{
4843
ArgumentUtility.CheckNotNull("typeDiscoveryService", typeDiscoveryService);
4944

Remotion/Core/ServiceLocation.PerformanceTestConsole/Program.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,25 @@
1515
// along with re-motion; if not, see http://www.gnu.org/licenses.
1616
//
1717
using System;
18+
using System.ComponentModel.Design;
1819
using System.Linq;
1920
using log4net.Config;
20-
using Remotion.Reflection;
21-
using Remotion.ServiceLocation;
2221
using Remotion.Utilities;
2322

24-
namespace Core.ServiceLocation.PerformanceTestConsole
23+
namespace Remotion.ServiceLocation.PerformanceTestConsole
2524
{
2625
internal static class Program
2726
{
2827
private static void Main (string[] args)
2928
{
3029
Console.WriteLine("{0} - Application started", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss,fff"));
3130
XmlConfigurator.Configure();
32-
var typeDiscoveryService = ContextAwareTypeUtility.GetTypeDiscoveryService();
31+
32+
var bootstrapServiceLocatorEntries = SafeServiceLocator.BootstrapConfiguration.GetRegistrations();
33+
var provider = new DefaultServiceLocatorProvider(new BootstrapServiceConfigurationDiscoveryService());
34+
var bootstrapServiceLocator = provider.GetServiceLocator(bootstrapServiceLocatorEntries);
35+
var typeDiscoveryService = bootstrapServiceLocator.GetInstance<ITypeDiscoveryService>();
36+
3337
var domainObjectType = Type.GetType("Remotion.Data.DomainObjects.DomainObject, Remotion.Data.DomainObjects", true, false);
3438
typeDiscoveryService.GetTypes(domainObjectType, false);
3539
typeDiscoveryService.GetTypes(domainObjectType, false);

Remotion/Core/UnitTests/Configuration/TypeDiscovery/IntegrationTests/SpecificRootAssemblies/SpecificRootAssembliesAreNotSubjectToApplicationFilterTest.cs

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)