feixian_weifajianguan/Infrastructure/Extensions/AutofacManager/AutofacContainerModule.cs

23 lines
712 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
namespace Infrastructure.Extensions.AutofacManager
{
/// <summary>
/// 提供全局静态获取服务的能力。
/// <para>例AutofacContainerModule.GetService&lt;IPathProvider&gt;()</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);
}
}
}