增加Prism 框架
This commit is contained in:
1 parent
2cd6b8db86
commit
726eb6de16
99 files changed
+12527
No files matched your search
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace MAX.Core.Autofac
|
||||
{
|
||||
/// <summary>
|
||||
/// 自动填充属性特性
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class AutowiredAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Autofac.Core;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MAX.Core.Autofac
|
||||
{
|
||||
/// <summary>
|
||||
/// autofac 找出所有属性上是否摸个特性
|
||||
/// </summary>
|
||||
public class CustomPropertySelector : IPropertySelector
|
||||
{
|
||||
public bool InjectProperty(PropertyInfo propertyInfo, object instance)
|
||||
{
|
||||
if (propertyInfo.CustomAttributes.Any(iterator => iterator.AttributeType == typeof(AutowiredAttribute)))
|
||||
{
|
||||
|
||||
}
|
||||
//需要一个判断
|
||||
//;如果标记的有CustomPropertyAttribute特性返回True:返回true;就构造实例
|
||||
return propertyInfo.CustomAttributes.Any(iterator => iterator.AttributeType == typeof(AutowiredAttribute));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Autofac;
|
||||
|
||||
namespace MAX.Core.Autofac
|
||||
{
|
||||
public interface IDependencyRegistrar
|
||||
{
|
||||
void Register(ContainerBuilder builder);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
using Autofac;
|
||||
using Autofac.Core;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MAX.Core.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// 容器
|
||||
/// </summary>
|
||||
public static partial class IocManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认容器
|
||||
/// </summary>
|
||||
public static IContainer Container { get; internal set; }
|
||||
public static void SetContainer(IContainer container)
|
||||
{
|
||||
Container = container;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 确定指定的服务在上下文中是否可用。
|
||||
/// </summary>
|
||||
/// <typeparam name="TService"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static bool IsRegistered<TService>()
|
||||
{
|
||||
return Container.IsRegistered<TService>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 确定指定的服务在上下文中是否可用。
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsRegistered(Type serverType)
|
||||
{
|
||||
return Container.IsRegistered(serverType);
|
||||
}
|
||||
|
||||
public static TService Resolve<TService>()
|
||||
{
|
||||
if (Container.IsRegistered<TService>())
|
||||
{
|
||||
return Container.Resolve<TService>();
|
||||
}
|
||||
return default;
|
||||
}
|
||||
public static object Resolve(Type serviceType)
|
||||
{
|
||||
if (Container.IsRegistered(serviceType))
|
||||
{
|
||||
return Container.Resolve(serviceType);
|
||||
}
|
||||
return default;
|
||||
}
|
||||
public static TService Resolve<TService>(params Parameter[] parameters)
|
||||
{
|
||||
if (Container.IsRegistered<TService>())
|
||||
{
|
||||
return Container.Resolve<TService>(parameters);
|
||||
}
|
||||
return default;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取所有注册
|
||||
/// </summary>
|
||||
/// <typeparam name="TService"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static TService[] ResolveAll<TService>()
|
||||
{
|
||||
return ResolveAll(typeof(TService)) as TService[];
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取所有注册
|
||||
/// </summary>
|
||||
/// <typeparam name="TService"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static object[] ResolveAll(Type type)
|
||||
{
|
||||
Type enumerableOfType = typeof(IEnumerable<>).MakeGenericType(type);
|
||||
return (object[])Container.ResolveService(new TypedService(enumerableOfType));
|
||||
}
|
||||
|
||||
public static Type GetRegistrationType(string key)
|
||||
{
|
||||
foreach (IComponentRegistration registration in Container.ComponentRegistry.Registrations)
|
||||
{
|
||||
foreach (Service service in registration.Services)
|
||||
{
|
||||
if (service is KeyedService ks)
|
||||
{
|
||||
if (key.Equals(ks.ServiceKey.ToString(), StringComparison.Ordinal))
|
||||
{
|
||||
if (Container.ComponentRegistry.TryGetServiceRegistration(service, out ServiceRegistration serviceRegistration))
|
||||
{
|
||||
return serviceRegistration.Registration.Target.Activator.LimitType;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user