diff --git a/src/Microsoft.AspNet.CoreServices/ActivatorUtilities.cs b/src/Microsoft.AspNet.CoreServices/ActivatorUtilities.cs deleted file mode 100644 index 45f4222569..0000000000 --- a/src/Microsoft.AspNet.CoreServices/ActivatorUtilities.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using System.Diagnostics.Contracts; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; - -namespace Microsoft.AspNet.CoreServices -{ - /// - /// Helper code for the various activator services. - /// - public static class ActivatorUtilities - { - /// - /// Retrieve an instance of the given type from the service provider. If one is not found then instantiate it directly. - /// - /// - /// - /// - public static object GetServiceOrCreateInstance(IServiceProvider services, Type type) - { - return GetServiceNoExceptions(services, type) ?? CreateInstance(services, type); - } - - [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "IServiceProvider may throw unknown exceptions")] - private static object GetServiceNoExceptions(IServiceProvider services, Type type) - { - try - { - return services.GetService(type); - } - catch - { - return null; - } - } - - /// - /// Instantiate an object of the given type, using constructor service injection if possible. - /// - /// - /// - /// - public static object CreateInstance(IServiceProvider services, Type type) - { - return CreateFactory(type).Invoke(services); - } - - /// - /// Creates a factory to instantiate a type using constructor service injection if possible. - /// - /// - /// - public static Func CreateFactory(Type type) - { - if (type == null) - { - throw new ArgumentNullException("type"); - } - - ConstructorInfo[] constructors = type.GetTypeInfo() - .DeclaredConstructors - .Where(IsInjectable) - .ToArray(); - - if (constructors.Length == 1) - { - ParameterInfo[] parameters = constructors[0].GetParameters(); - return services => - { - var args = new object[parameters.Length]; - for (int index = 0; index != parameters.Length; ++index) - { - args[index] = services.GetService(parameters[index].ParameterType); - } - return Activator.CreateInstance(type, args); - }; - } - return _ => Activator.CreateInstance(type); - } - - private static bool IsInjectable(ConstructorInfo constructor) - { - return constructor.IsPublic && constructor.GetParameters().Length != 0; - } - - public static Func Create(Type instanceType) where TBase : class - { - Contract.Assert(instanceType != null); - NewExpression newInstanceExpression = Expression.New(instanceType); - return Expression.Lambda>(newInstanceExpression).Compile(); - } - - public static Func Create() where TInstance : class - { - return Create(typeof(TInstance)); - } - - public static Func Create(Type instanceType) - { - Contract.Assert(instanceType != null); - return Create(instanceType); - } - } -} diff --git a/src/Microsoft.AspNet.CoreServices/Microsoft.AspNet.CoreServices.csproj b/src/Microsoft.AspNet.CoreServices/Microsoft.AspNet.CoreServices.csproj deleted file mode 100644 index 2b2db0a0e9..0000000000 --- a/src/Microsoft.AspNet.CoreServices/Microsoft.AspNet.CoreServices.csproj +++ /dev/null @@ -1,59 +0,0 @@ - - - - - Debug - AnyCPU - {EC38534C-A2D1-413F-97D1-55EEF5D2FB71} - Library - Properties - Microsoft.AspNet.CoreServices - Microsoft.AspNet.CoreServices - v4.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\..\packages\Microsoft.Owin.FileSystems.2.1.0-rc1\lib\net40\Microsoft.Owin.FileSystems.dll - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Microsoft.AspNet.CoreServices/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.CoreServices/Properties/AssemblyInfo.cs deleted file mode 100644 index b671463e0b..0000000000 --- a/src/Microsoft.AspNet.CoreServices/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Microsoft.AspNet.CoreServices")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Microsoft.AspNet.CoreServices")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("96e86a39-7c32-4257-af76-d12e449dc25a")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Microsoft.AspNet.CoreServices/ServiceProvider.cs b/src/Microsoft.AspNet.CoreServices/ServiceProvider.cs deleted file mode 100644 index 8123fecf41..0000000000 --- a/src/Microsoft.AspNet.CoreServices/ServiceProvider.cs +++ /dev/null @@ -1,164 +0,0 @@ -using System; -using System.Reflection; -using System.Collections; -using System.Collections.Generic; -using System.Linq; - -namespace Microsoft.AspNet.CoreServices -{ - /// - /// The default IServiceProvider. - /// - public class ServiceProvider : IServiceProvider - { - private readonly IDictionary> _services = new Dictionary>(); - private readonly IDictionary>> _priorServices = new Dictionary>>(); - - /// - /// - /// - public ServiceProvider() - { - _services[typeof(IServiceProvider)] = () => this; - } - - /// - /// Gets the service object of the specified type. - /// - /// - /// - public virtual object GetService(Type serviceType) - { - return GetSingleService(serviceType) ?? GetMultiService(serviceType); - } - - private object GetSingleService(Type serviceType) - { - Func serviceFactory; - return _services.TryGetValue(serviceType, out serviceFactory) - ? serviceFactory.Invoke() - : null; - } - - private object GetMultiService(Type collectionType) - { - if (collectionType.GetTypeInfo().IsGenericType && - collectionType.GetGenericTypeDefinition() == typeof(IEnumerable<>)) - { - Type serviceType = collectionType.GetTypeInfo().GenericTypeArguments.Single(); - Type listType = typeof(List<>).MakeGenericType(serviceType); - var services = (IList)Activator.CreateInstance(listType); - - Func serviceFactory; - if (_services.TryGetValue(serviceType, out serviceFactory)) - { - services.Add(serviceFactory()); - - List> prior; - if (_priorServices.TryGetValue(serviceType, out prior)) - { - foreach (var factory in prior) - { - services.Add(factory()); - } - } - } - return services; - } - return null; - } - - /// - /// Remove all occurrences of the given type from the provider. - /// - /// - /// - public virtual ServiceProvider RemoveAll() - { - return RemoveAll(typeof(T)); - } - - /// - /// Remove all occurrences of the given type from the provider. - /// - /// - /// - public virtual ServiceProvider RemoveAll(Type type) - { - _services.Remove(type); - _priorServices.Remove(type); - return this; - } - - /// - /// Add an instance of type TService to the list of providers. - /// - /// - /// - /// - public virtual ServiceProvider AddInstance(object instance) - { - return AddInstance(typeof(TService), instance); - } - - /// - /// Add an instance of the given type to the list of providers. - /// - /// - /// - /// - public virtual ServiceProvider AddInstance(Type service, object instance) - { - return Add(service, () => instance); - } - - /// - /// Specify that services of the type TService should be fulfilled by the type TImplementation. - /// - /// - /// - /// - public virtual ServiceProvider Add() - { - return Add(typeof(TService), typeof(TImplementation)); - } - - /// - /// Specify that services of the type serviceType should be fulfilled by the type implementationType. - /// - /// - /// - /// - public virtual ServiceProvider Add(Type serviceType, Type implementationType) - { - Func factory = ActivatorUtilities.CreateFactory(implementationType); - return Add(serviceType, () => factory(this)); - } - - /// - /// Specify that services of the given type should be created with the given serviceFactory. - /// - /// - /// - /// - public virtual ServiceProvider Add(Type serviceType, Func serviceFactory) - { - Func existing; - if (_services.TryGetValue(serviceType, out existing)) - { - List> prior; - if (_priorServices.TryGetValue(serviceType, out prior)) - { - prior.Add(existing); - } - else - { - prior = new List> { existing }; - _priorServices.Add(serviceType, prior); - } - } - _services[serviceType] = serviceFactory; - return this; - } - } -} diff --git a/src/Microsoft.AspNet.CoreServices/ServiceProviderExtensions.cs b/src/Microsoft.AspNet.CoreServices/ServiceProviderExtensions.cs deleted file mode 100644 index 4e9c1ce184..0000000000 --- a/src/Microsoft.AspNet.CoreServices/ServiceProviderExtensions.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace Microsoft.AspNet.CoreServices -{ - public static class ServiceProviderExtensions - { - /// - /// Retrieve a service of type T from the IServiceProvider. - /// - /// - /// - /// - public static T GetService(this IServiceProvider services) - { - if (services == null) - { - throw new ArgumentNullException("services"); - } - - return (T)services.GetService(typeof(T)); - } - } -} diff --git a/src/Microsoft.AspNet.CoreServices/packages.config b/src/Microsoft.AspNet.CoreServices/packages.config deleted file mode 100644 index 1fc33b3767..0000000000 --- a/src/Microsoft.AspNet.CoreServices/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/Microsoft.AspNet.CoreServices/project.json b/src/Microsoft.AspNet.CoreServices/project.json deleted file mode 100644 index d8a96bf94c..0000000000 --- a/src/Microsoft.AspNet.CoreServices/project.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "dependencies": { - "Microsoft.Owin.FileSystems": "2.0.2" - }, - "configurations": { - "net45": {}, - "k10": {} - } -} \ No newline at end of file