コード例 #1
0
ファイル: IocManager.cs プロジェクト: ShaunChen-mps/XR
        private void AddContainer(Type type, ContainerAttribute attrContainer, bool isNew = false)
        {
            var logger = new UnitLogger("IocManager");

            if (type.GetInterfaces().Where(p => p.FullName == attrContainer.BaseType.FullName).Count() == 0 && type.BaseType != attrContainer.BaseType)
            {
                logger.Error($"类型{type.FullName}没有继承自{attrContainer.BaseType.FullName},无法注册到容器");
            }
            else
            {
                var key = new ContainerKey(attrContainer.ModuleName, attrContainer.BaseType.FullName);
                if (ContainerDic.Keys.Contains(key))
                {
                    if (isNew)
                    {
                        ContainerDic.Remove(key);
                    }
                    else
                    {
                        logger.Warn($"类型:{type.FullName},模块:{attrContainer.ModuleName},继承自{attrContainer.BaseType.FullName},已经注册到容器,无法再次注册");
                    }
                }
                var args = new ContainerArgs(type, attrContainer);
                logger.Info($"类型:{type.FullName},模块:{attrContainer.ModuleName},继承自{attrContainer.BaseType.FullName},成功注册到容器");
                ContainerDic.Add(key, args);
            }
        }
コード例 #2
0
ファイル: ContainerArgs.cs プロジェクト: ShaunChen-mps/XR
 public ContainerArgs(Type type, ContainerAttribute containerAttribute)
 {
     this.Type = type;
     this.ContainerAttribute = containerAttribute;
 }