123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using Autofac;
- using Microsoft.AspNetCore.Http;
- using Serilog;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace DW5S.Repostory
- {
- public static class IocContainer
- {
- public static void Init(ILifetimeScope container)
- {
- Container = container;
- Logger=GetService<ILogger>();
- }
- private static ILifetimeScope Container;
- public static ILogger Logger { get; private set; }
- public static IUnitOfWork UnitOfWork
- {
- get
- {
- return GetService<IUnitOfWork>();
- }
- }
- public static T GetService<T>() where T : class
- {
- var scop = Container.BeginLifetimeScope();
- return scop.Resolve<T>();
- }
- public static T GetService<T>(object parameter) where T : class
- {
- var scop = Container.BeginLifetimeScope();
- return scop.Resolve<T>( new TypedParameter(parameter.GetType(), parameter));
- }
- }
- }
|