/NuGet/Build/WindowsRuntime/LightInject.ServiceLocation/LightInject.ServiceLocation.cs
https://github.com/dancky/LightInject · C# · 82 lines · 31 code · 6 blank · 45 comment · 2 complexity · c04ae0a7ff3071367be5aadfcbecd919 MD5 · raw file
- /*****************************************************************************
- The MIT License (MIT)
- Copyright (c) 2013 bernhard.richter@gmail.com
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- ******************************************************************************
- LightInject.ServiceLocation version 1.0.0.2
- http://seesharper.github.io/LightInject/
- http://twitter.com/bernhardrichter
- ******************************************************************************/
- [module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1126:PrefixCallsCorrectly", Justification = "Reviewed")]
- [module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "No inheritance")]
- [module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Single source file deployment.")]
- [module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:FileMustHaveHeader", Justification = "Custom header.")]
- [module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "All public members are documented.")]
- namespace LightInject.ServiceLocation
- {
- using System;
- using System.Collections.Generic;
- using Microsoft.Practices.ServiceLocation;
- /// <summary>
- /// An <see cref="IServiceLocator"/> adapter for the LightInject service container.
- /// </summary>
- public class LightInjectServiceLocator : ServiceLocatorImplBase
- {
- private readonly IServiceContainer serviceContainer;
- /// <summary>
- /// Initializes a new instance of the <see cref="LightInjectServiceLocator"/> class.
- /// </summary>
- /// <param name="serviceContainer">The <see cref="IServiceContainer"/> instance wrapped by this class.</param>
- public LightInjectServiceLocator(IServiceContainer serviceContainer)
- {
- this.serviceContainer = serviceContainer;
- }
- /// <summary>
- /// Gets a named instance of the given <paramref name="serviceType"/>.
- /// </summary>
- /// <param name="serviceType">The type of the requested service.</param>
- /// <param name="key">The key of the requested service.</param>
- /// <returns>The requested service instance.</returns>
- protected override object DoGetInstance(Type serviceType, string key)
- {
- if (key != null)
- {
- return serviceContainer.GetInstance(serviceType, key);
- }
-
- return serviceContainer.GetInstance(serviceType);
- }
- /// <summary>
- /// Gets all instances of the given <paramref name="serviceType"/>.
- /// </summary>
- /// <param name="serviceType">The type of services to resolve.</param>
- /// <returns>A list that contains all implementations of the <paramref name="serviceType"/>.</returns>
- protected override IEnumerable<object> DoGetAllInstances(Type serviceType)
- {
- return serviceContainer.GetAllInstances(serviceType);
- }
- }
- }