Пример #1
0
        void RegisterClass(Type classType, Type interfaceType)
        {
            bool firstLevel = (null == interfaceType);

            Type[] interfaces = (firstLevel ? classType : interfaceType).GetInterfaces();

            bool forcedSingletion = false;

            foreach (Type i in interfaces)
            {
                if (i == _singleFactable)
                {
                    forcedSingletion = true;
                    break;
                }
            }
            foreach (Type i in interfaces)
            {
                if ((i != _singleFactable) && (i != _factableType) &&
                    _factableType.IsAssignableFrom(i))
                {
                    ComponentRegistration descriptor = new ComponentRegistration(classType);
                    descriptor.ServiceType = i;
                    descriptor.IsSingleton = (forcedSingletion || _singleFactable.IsAssignableFrom(i));
                    try
                    {
                        _container.Register(descriptor);
                    }
                    catch (Exception ex)
                    {
#if DEBUG
                        System.Diagnostics.Debug.WriteLine(
                            string.Format("无法将类型 '{0}' 注册为 '{1}',发生了异常:{2}",
                                          classType.FullName,
                                          i.FullName,
                                          ex.Message));
#endif
                    }
                }
                RegisterClass(classType, i);
            }
        }
Пример #2
0
        void hwnd_OnRegister(object sender, EventArgs e)
        {
            ComponentRegistration hwnd = sender as ComponentRegistration;

            InternalRegister(hwnd);
        }
Пример #3
0
 public void Register(ComponentRegistration registration)
 {
     InternalRegister(registration);
 }
Пример #4
0
 protected virtual void CloneInstance(ComponentRegistration targetInstance)
 {
 }