添加项目文件。

This commit is contained in:
chfei committed 2026-10-26 18:21:42 +08:00
1 parent 54c7b83029
commit ef50fa0620
84 files changed
+9188

No files matched your search

@@ -0,0 +1,5 @@
namespace MAX.Core.DependencyInjection;
public interface INoDependency
{
}
@@ -0,0 +1,8 @@
namespace MAX.Core.DependencyInjection;
/// <summary>
/// 单例
/// </summary>
public interface ISingletonDependency
{
}
@@ -0,0 +1,8 @@
namespace MAX.Core.DependencyInjection;
/// <summary>
/// 每次实例化
/// </summary>
public interface ITransientDependency
{
}
@@ -0,0 +1,37 @@
using MAX.Core.Autofac;
using MAX.Core.Infrastructure;
using System;
using System.Collections.Concurrent;
namespace MAX.Core.DependencyInjection;
public interface ILazyServiceProvider
{
object LazyGetService(Type serviceType);
T LazyGetService<T>();
}
public class LazyServiceProvider : SingleInstance<LazyServiceProvider>, ILazyServiceProvider
{
protected ConcurrentDictionary<Type, Lazy<object>> CachedServices { get; }
private LazyServiceProvider()
{
CachedServices = new ConcurrentDictionary<Type, Lazy<object>>();
}
public virtual T LazyGetService<T>()
{
return (T)LazyGetService(typeof(T));
}
public virtual object LazyGetService(Type serviceType)
{
return GetService(serviceType);
}
public virtual object GetService(Type serviceType)
{
return CachedServices.GetOrAdd(
serviceType,
_ => new Lazy<object>(() => IocManager.Resolve(serviceType))
).Value;
}
}