private void TriggerOnCreating(object sender, ComponentCreatingEventArgs e)
 {
     if (e.CreatedObject is IOnCreating listener)
     {
         listener.OnCreating(new CreateArguments(e.ComponentManager, e.RequiredType));
     }
 }
Ejemplo n.º 2
0
        private ProxyOnTypeInfo GetProxyInfo(ComponentCreatingEventArgs e)
        {
            Type type = e.CreatedObject.GetType();
            bool isDynamicImplemented = e.CreatedObject.IsDynamicImplemented();

            if (isDynamicImplemented)
            {
                type = e.RequiredType;
            }

            Debug.WriteLine("GetProxyInfo({0})", type);
            return(cacheForProxyInfo.GetOrAdd(type, key => CreateProxyInfo(type, isDynamicImplemented)));
        }
Ejemplo n.º 3
0
        private void ComponentRegistration_Activating(object sender, ActivatingEventArgs <object> e)
        {
            IComponentRegistration     registration = sender as IComponentRegistration;
            ComponentCreatingEventArgs moduleComponentCreatingEventArgs =
                new ComponentCreatingEventArgs(new ComponentContextComponentManager(e.Context), serviceType, e.Instance);

            Debug.WriteLine($"[{registration.Id}] ComponentCreating : {moduleComponentCreatingEventArgs}");
            this.ComponentCreating?.Invoke(this, moduleComponentCreatingEventArgs);
            if (moduleComponentCreatingEventArgs.IsReplaced)
            {
                Debug.WriteLine($"[{registration.Id}] ComponentReplaced : {moduleComponentCreatingEventArgs.ReplacedObject.GetType()} : {moduleComponentCreatingEventArgs.RequiredType}");
                e.Instance = moduleComponentCreatingEventArgs.ReplacedObject;
            }
        }
Ejemplo n.º 4
0
        private void Registration_Activating(object sender, ActivatingEventArgs <object> e)
        {
            IComponentRegistration registration = sender as IComponentRegistration;
            Type serviceType = registration.Metadata["ServiceType"] as Type;
            ComponentCreatingEventArgs moduleComponentCreatingEventArgs =
                new ComponentCreatingEventArgs(new ComponentContextComponentManager(e.Context), serviceType, e.Instance);

            Debug.WriteLine($"[{registration.Id}] ComponentCreating : {moduleComponentCreatingEventArgs}");
            this.ComponentCreating?.Invoke(this, moduleComponentCreatingEventArgs);
            if (moduleComponentCreatingEventArgs.IsReplaced)
            {
                e.Instance = moduleComponentCreatingEventArgs.ReplacedObject;
            }
        }
Ejemplo n.º 5
0
        private void ComponentContainer_ComponentCreating(object sender, ComponentCreatingEventArgs e)
        {
            if (!e.RequiredType.IsInterface)
            {
                return;
            }

            var proxyOnTypeInfo = GetProxyInfo(e);

            if (proxyOnTypeInfo.ProxyTypesOnClass.Count == 0 && proxyOnTypeInfo.ProxyTypsOnMethodMap.Count == 0)
            {
                return;
            }

            var proxyOnTypeRuntimeInfo = new ProxyOnTypeRuntimeInfo(e.ComponentManager, proxyOnTypeInfo);
            ProxyAttributeExecuteInterceptor proxyAttributeExecuteInterceptor = new ProxyAttributeExecuteInterceptor(proxyOnTypeRuntimeInfo);
            var newInstance = proxyGenerator.CreateInterfaceProxyWithTarget(
                e.RequiredType,
                e.CreatedObject,
                proxyAttributeExecuteInterceptor
                );

            e.Replace(newInstance);
        }
Ejemplo n.º 6
0
 private void ComponentContainer_ComponentCreating(object sender, ComponentCreatingEventArgs e)
 {
 }
 private void ComponentContainer_ComponentCreating(object sender, ComponentCreatingEventArgs e)
 {
     Console.WriteLine("TestContainer : {0} -> {1}", e.RequiredType, e.CreatedObject.GetType());
 }