OpenAuth.Net/Infrastructure/Extensions/AutofacManager/AutofacContainerModule.cs
2020-10-22 14:59:36 +08:00

23 lines
706 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
namespace Infrastructure.Extensions.AutofacManager
{
/// <summary>
/// 提供全局静态获取服务的能力。
/// <para>例AutofacContainerModule.GetService<IPathProvider>()</para>
/// </summary>
public class AutofacContainerModule
{
static private IServiceProvider _provider;
public static void ConfigServiceProvider(IServiceProvider serviceProvider)
{
_provider = serviceProvider;
}
public static TService GetService<TService>() where TService:class
{
Type typeParameterType = typeof(TService);
return (TService)_provider.GetService(typeParameterType);
}
}
}