private void TriggerOnCreating(object sender, ComponentCreatingEventArgs e) { if (e.CreatedObject is IOnCreating listener) { listener.OnCreating(new CreateArguments(e.ComponentManager, e.RequiredType)); } }
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))); }
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; } }
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; } }
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); }
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()); }