Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/RM-5931-Support-for-Bootstrapping-in-ServiceLocator #1037

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@

namespace Remotion.Configuration.ServiceLocation
{
[Obsolete("Use IoC bootstrapping to resolve the IServiceLocatorProvider (Version 6.0.0)", true)]
public interface IServiceLocationConfiguration
{
/// <summary>
/// Creates an <see cref="IServiceLocatorProvider"/> instance as indicated by <see cref="ServiceLocationConfiguration.ServiceLocatorProvider"/>. If no
/// <see cref="ServiceLocationConfiguration.ServiceLocatorProvider"/> is set, an instance of <see cref="DefaultServiceLocatorProvider"/> is returned.
/// </summary>
/// <returns>An new <see cref="IServiceLocatorProvider"/> instance.</returns>
[Obsolete("Use IoC bootstrapping to resolve the IServiceLocatorProvider (Version 6.0.0)", true)]
IServiceLocatorProvider CreateServiceLocatorProvider ();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is part of the re-motion Core Framework (www.re-motion.org)
// This file is part of the re-motion Core Framework (www.re-motion.org)
// Copyright (c) rubicon IT GmbH, www.rubicon.eu
//
// The re-motion Core Framework is free software; you can redistribute it
Expand All @@ -15,16 +15,18 @@
// along with re-motion; if not, see http://www.gnu.org/licenses.
//
using System;
using System.Collections.ObjectModel;
using Remotion.ServiceLocation;

namespace Remotion.UnitTests.Configuration.ServiceLocation
namespace Remotion.Configuration.ServiceLocation
{
public class FakeServiceLocatorProvider : IServiceLocatorProvider
[Obsolete("Use IoC bootstrapping to resolve the IServiceLocatorProvider (Version 6.0.0)", true)]

public static class ServiceLocationConfiguration
{
public IServiceLocator GetServiceLocator (ReadOnlyCollection<ServiceConfigurationEntry> bootstrapConfiguration)
[Obsolete("Use IoC bootstrapping to resolve the IServiceLocatorProvider (Version 6.0.0)", true)]

public static IServiceLocationConfiguration Current
{
throw new NotImplementedException();
get => throw new NotSupportedException("Use IoC bootstrapping to resolve the IServiceLocatorProvider (Version 6.0.0)");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,153 +70,13 @@ public TypeDiscoveryConfiguration ()
}

/// <summary>
/// Gets or sets the <see cref="TypeDiscoveryMode"/> to be used for type discovery.
/// </summary>
/// <value>The <see cref="TypeDiscoveryMode"/> to be used for type discovery.</value>
[ConfigurationProperty("mode", DefaultValue = TypeDiscoveryMode.Automatic, IsRequired = false)]
public TypeDiscoveryMode Mode
{
get { return (TypeDiscoveryMode)this["mode"]; }
set { this["mode"] = value; }
}

/// <summary>
/// Gets a <see cref="TypeElement{TBase}"/> describing the custom <see cref="IRootAssemblyFinder"/> to be used. This is only relevant
/// if <see cref="Mode"/> is set to <see cref="TypeDiscoveryMode.CustomRootAssemblyFinder"/>. In this mode, an
/// <see cref="AssemblyFinderTypeDiscoveryService"/> is created, and an instance of the specified <see cref="CustomRootAssemblyFinder"/> type is
/// employed for finding the root assemblies used for type discovery. The given type must have a default constructor.
/// </summary>
/// <value>A <see cref="TypeElement{TBase}"/> describing the custom <see cref="IRootAssemblyFinder"/> type to be used.</value>
[ConfigurationProperty("customRootAssemblyFinder", IsRequired = false)]
public TypeElement<IRootAssemblyFinder> CustomRootAssemblyFinder
{
get { return (TypeElement<IRootAssemblyFinder>)this["customRootAssemblyFinder"]; }
}

/// <summary>
/// Gets a <see cref="RootAssembliesElement"/> describing specific root assemblies to be used. This is only relevant
/// if <see cref="Mode"/> is set to <see cref="TypeDiscoveryMode.SpecificRootAssemblies"/>. In this mode, an
/// <see cref="AssemblyFinderTypeDiscoveryService"/> is created, and the given root assemblies are employed for type discovery.
/// Note that even if an assembly is specified as a root assembly, the default filtering rules (<see cref="ApplicationAssemblyLoaderFilter"/>)
/// still apply even for that assembly.
/// Gets a <see cref="RootAssembliesElement"/> describing specific root assemblies to be used.
/// </summary>
/// <value>A <see cref="RootAssembliesElement"/> describing specific root assemblies to be used.</value>
[ConfigurationProperty("specificRootAssemblies", IsRequired = false)]
public RootAssembliesElement SpecificRootAssemblies
{
get { return (RootAssembliesElement)this["specificRootAssemblies"]; }
}

/// <summary>
/// Gets a <see cref="TypeElement{TBase}"/> describing the custom <see cref="ITypeDiscoveryService"/> to be used. This is only relevant
/// if <see cref="Mode"/> is set to <see cref="TypeDiscoveryMode.CustomTypeDiscoveryService"/>. In this mode, an
/// instance of the specified <see cref="CustomTypeDiscoveryService"/> type is
/// employed for type discovery. The given type must have a default constructor.
/// </summary>
/// <value>A <see cref="TypeElement{TBase}"/> describing the custom <see cref="ITypeDiscoveryService"/> type to be used.</value>
[ConfigurationProperty("customTypeDiscoveryService", IsRequired = false)]
public TypeElement<ITypeDiscoveryService> CustomTypeDiscoveryService
{
get { return (TypeElement<ITypeDiscoveryService>)this["customTypeDiscoveryService"]; }
}

/// <summary>
/// Creates an <see cref="ITypeDiscoveryService"/> instance as indicated by <see cref="Mode"/>.
/// </summary>
/// <returns>A new <see cref="ITypeDiscoveryService"/> that discovers types as indicated by <see cref="Mode"/>.</returns>
public ITypeDiscoveryService CreateTypeDiscoveryService ()
{
switch (Mode)
{
case TypeDiscoveryMode.CustomRootAssemblyFinder:
return CreateServiceWithCustomRootAssemblyFinder();
case TypeDiscoveryMode.SpecificRootAssemblies:
return CreateServiceWithSpecificRootAssemblies();
case TypeDiscoveryMode.CustomTypeDiscoveryService:
return CreateCustomService();
default:
return CreateServiceWithAutomaticDiscovery();
}
}

private ITypeDiscoveryService CreateServiceWithCustomRootAssemblyFinder ()
{
if (CustomRootAssemblyFinder.Type == null)
{
string message = string.Format(
"In CustomRootAssemblyFinder mode, a custom root assembly finder must be specified in the type discovery configuration. {0}",
GetConfigurationBodyErrorMessage(
"CustomRootAssemblyFinder",
"<customRootAssemblyFinder type=\"ApplicationNamespace.CustomFinderType, ApplicationAssembly\"/>"));
throw new ConfigurationErrorsException(message);
}

// TODO RM-7788: The return value of Activator.CreateInstance should be checked for null.
var customRootAssemblyFinder = (IRootAssemblyFinder)Activator.CreateInstance(CustomRootAssemblyFinder.Type)!;
return CreateServiceWithAssemblyFinder(customRootAssemblyFinder);
}

private ITypeDiscoveryService CreateServiceWithSpecificRootAssemblies ()
{
var assemblyLoader = CreateAllAssemblyLoader();
var rootAssemblyFinder = SpecificRootAssemblies.CreateRootAssemblyFinder(assemblyLoader);
return CreateServiceWithAssemblyFinder(rootAssemblyFinder);
}

private ITypeDiscoveryService CreateCustomService ()
{
if (CustomTypeDiscoveryService.Type == null)
{
string message = string.Format(
"In CustomTypeDiscoveryService mode, a custom type discovery service must be specified in the type discovery configuration. {0}",
GetConfigurationBodyErrorMessage(
"CustomTypeDiscoveryService",
"<customTypeDiscoveryService type=\"ApplicationNamespace.CustomServiceType, ApplicationAssembly\"/>"));
throw new ConfigurationErrorsException(message);
}

// TODO RM-7788: The return value of Activator.CreateInstance should be checked for null.
return (ITypeDiscoveryService)Activator.CreateInstance(CustomTypeDiscoveryService.Type)!;
}

private ITypeDiscoveryService CreateServiceWithAutomaticDiscovery ()
{
var assemblyLoader = CreateApplicationAssemblyLoader();
var searchPathRootAssemblyFinder = SearchPathRootAssemblyFinder.CreateForCurrentAppDomain(false, assemblyLoader);
return CreateServiceWithAssemblyFinder(searchPathRootAssemblyFinder);
}

private ITypeDiscoveryService CreateServiceWithAssemblyFinder (IRootAssemblyFinder customRootAssemblyFinder)
{
var filteringAssemblyLoader = CreateApplicationAssemblyLoader();
var assemblyFinder = new CachingAssemblyFinderDecorator(new AssemblyFinder(customRootAssemblyFinder, filteringAssemblyLoader));
return new AssemblyFinderTypeDiscoveryService(assemblyFinder);
}

private string GetConfigurationBodyErrorMessage (string modeValue, string modeSpecificBodyElement)
{
var message = Environment.NewLine + Environment.NewLine
+ "Example configuration: " + Environment.NewLine
+ "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + Environment.NewLine
+ "<configuration>" + Environment.NewLine
+ " <configSections>" + Environment.NewLine
+ " <section name=\"remotion.typeDiscovery\" type=\"Remotion.Configuration.TypeDiscovery.TypeDiscoveryConfiguration, Remotion\" />" + Environment.NewLine
+ " </configSections>" + Environment.NewLine
+ " <remotion.typeDiscovery xmlns=\"http://www.re-motion.org/typeDiscovery/configuration\" mode=\"" + modeValue + "\">" + Environment.NewLine
+ " " + modeSpecificBodyElement + Environment.NewLine
+ " </remotion.typeDiscovery>" + Environment.NewLine
+ "</configuration>";
return message;
}

private IAssemblyLoader CreateApplicationAssemblyLoader ()
{
return new FilteringAssemblyLoader(ApplicationAssemblyLoaderFilter.Instance);
}

private IAssemblyLoader CreateAllAssemblyLoader ()
{
return new FilteringAssemblyLoader(new LoadAllAssemblyLoaderFilter());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// along with re-motion; if not, see http://www.gnu.org/licenses.
//
using System;
using System.ComponentModel.Design;
using Remotion.Reflection.TypeDiscovery.AssemblyFinding;

namespace Remotion.Configuration.TypeDiscovery
{
Expand All @@ -30,22 +28,18 @@ public enum TypeDiscoveryMode
/// and their referenced assemblies.
/// </summary>
Automatic,
/// <summary>
/// Chooses a custom <see cref="IRootAssemblyFinder"/> which searches for root assemblies. The types are discovered from those assemblies.
/// Whether types from referenced assemblies are also included is defined by the <see cref="IRootAssemblyFinder"/>.
/// See <see cref="TypeDiscoveryConfiguration.CustomRootAssemblyFinder"/>.
/// </summary>

[Obsolete("Register the custom implementation of IRootAssemblyFinder via the SafeServiceLocator.BootstrapConfiguration. (Version 6.0.0)", true)]
CustomRootAssemblyFinder,

/// <summary>
/// Chooses a number of specific root assemblies. The types are discovered from those assemblies. Whether types from referenced assemblies are
/// also included is defined by the user.
/// See <see cref="TypeDiscoveryConfiguration.SpecificRootAssemblies"/>.
/// </summary>
SpecificRootAssemblies,
/// <summary>
/// Chooses a custom <see cref="ITypeDiscoveryService"/> implementation. The types are discovered by that service.
/// See <see cref="TypeDiscoveryConfiguration.CustomTypeDiscoveryService"/>.
/// </summary>

[Obsolete("Register the custom implementation of ITypeDiscoveryService via the SafeServiceLocator.BootstrapConfiguration. (Version 6.0.0)", true)]
CustomTypeDiscoveryService
}
}
Loading