CQRS_Simple/CQRS_Simple.Infrastructure/IocManager.cs

29 lines
629 B
C#
Raw Permalink Normal View History

2022-04-07 14:00:58 +08:00
using Autofac;
namespace CQRS_Simple.Infrastructure
{
public interface IIocManager
{
ILifetimeScope AutofacContainer { get; set; }
TService GetInstance<TService>();
}
public class IocManager : IIocManager
{
public IocManager(ILifetimeScope container)
{
AutofacContainer = container;
}
/// <summary>
/// Autofac容器
/// </summary>
public ILifetimeScope AutofacContainer { get; set; }
public TService GetInstance<TService>()
{
return AutofacContainer.Resolve<TService>();
}
}
}