Skip to content

Commit

Permalink
DIExtensions in english
Browse files Browse the repository at this point in the history
  • Loading branch information
turbcool committed Jul 21, 2023
1 parent 0617638 commit 384e52d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions NewPlatform.Flexberry.ORM.UnityFactory/DIExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
using Unity;

/// <summary>
/// Расширения для внедрения зависимостей.
/// Extensions for resolving dependencies.
/// </summary>
public static class DIExtensions
{
/// <summary>
/// Получить именованную зависимость с помощью IUnityContainer (IUnityContainer должен быть зарегистрирован в IServiceProvider).
/// Get a named dependency using IUnityContainer (IUnityContainer should be already registered at IServiceProvider).
/// </summary>
/// <typeparam name="T">Тип.</typeparam>
/// <param name="serviceProvider">IServiceProvider.</param>
/// <param name="name">Имя зависимости.</param>
/// <returns>Разрешенная зависимость.</returns>
/// <typeparam name="T">Type to resolve.</typeparam>
/// <param name="serviceProvider">A service provider. IUnityContainer container should be already registered.</param>
/// <param name="name">Name of the dependency.</param>
/// <returns>Resolved dependency.</returns>
/// <exception cref="InvalidOperationException">Ошибка получения именованной зависимости.</exception>
public static object GetService<T>(this IServiceProvider serviceProvider, string name)
public static T GetService<T>(this IServiceProvider serviceProvider, string name)
{
var unityContainer = serviceProvider.GetService(typeof(IUnityContainer));

if (unityContainer == null)
{
throw new InvalidOperationException($"Невозможно получить именнованную зависимость - IUnityContainer не зарегистрирован в этом ServiceProvider.");
throw new InvalidOperationException($"Unable to resolve - IUnityContainer not registered in this IServiceProvider.");
}
else
{
Expand Down

0 comments on commit 384e52d

Please sign in to comment.