コード例 #1
0
 /// <summary>
 /// Handles the <see cref="ExtensionContext.RegisteringInstance"/> event by
 /// ensuring that, if the lifetime manager is a  <see cref="SynchronizedLifetimeManager"/> that its
 /// <see cref="SynchronizedLifetimeManager.GetValue"/> method has been called.
 /// </summary>
 /// <param name="sender">The object responsible for raising the event.</param>
 /// <param name="e">A <see cref="RegisterInstanceEventArgs"/> containing the event's data.</param>
 private void PreRegisteringInstance(object sender, RegisterInstanceEventArgs e)
 {
     if (e.LifetimeManager is SynchronizedLifetimeManager)
     {
         e.LifetimeManager.GetValue();
     }
 }
 void OnContextRegisteringInstance(object sender, RegisterInstanceEventArgs args)
 {
     if (args.Name == null)
     {
         onRegisteringInstanceCallback(args.RegisteredType, args.Instance, args.LifetimeManager);
     }
 }
コード例 #3
0
        private void OnRegisteringInstance(object sender, RegisterInstanceEventArgs e)
        {
            m_Entries.Add(new TypeRegistrationEntry(e.RegisteredType, e.Name));

            if (RegisteringInstance != null)
            {
                RegisteringInstance(sender, e);
            }
        }
コード例 #4
0
 private void OnRegisteringInstance(object sender, RegisterInstanceEventArgs e)
 {
     if (string.IsNullOrEmpty(e.Name))
     {
         string uniqueName = Guid.NewGuid().ToString();
         this.Context.RegisterNamedType(e.RegisteredType, uniqueName);
         this.Context.Policies.Set <IBuildKeyMappingPolicy>(
             new BuildKeyMappingPolicy(new NamedTypeBuildKey(e.RegisteredType)),
             new NamedTypeBuildKey(e.RegisteredType, uniqueName));
     }
 }
コード例 #5
0
        private void OnRegisterInstance(object sender, RegisterInstanceEventArgs e)
        {
            var atts  = e.Instance.GetType().GetCustomAttributes(typeof(SystemImmutableComponentAttribute), false);
            var atts2 = e.RegisteredType.GetCustomAttributes(typeof(SystemImmutableComponentAttribute), false);

            if ((atts.Length > 0) || (atts2.Length > 0) &&
                (SistemComponentInstanceRegistered != null))
            {
                var duplicated = (_registeredInstances.Contains(e.Instance.GetType()) ||
                                  (_registeredInstances.Contains(e.RegisteredType)));

                SistemComponentInstanceRegistered(this, new InstanceRegisterEventArgs(e, duplicated));
            }

            AddInstance(e.Instance.GetType());
        }
コード例 #6
0
 private void Context_RegisteringInstance(object sender, RegisterInstanceEventArgs e)
 {
     if (e.LifetimeManager is ExecutionScopeLifetimeManager)
     {
         var lm     = e.LifetimeManager as ExecutionScopeLifetimeManager;
         var key    = new NamedTypeBuildKey(e.RegisteredType, e.Name);
         var newKey = new NamedTypeBuildKey(e.RegisteredType, $"{e.Name}_Scope_{lm.Scope.Key}");
         lm.SetValue(e.Instance);
         Context.Policies.Clear <ILifetimePolicy>(key);
         Context.Policies.Set <ILifetimePolicy>(lm, newKey);
         Context.Policies.Set <IExecutionScopeLifetimePolicy>(lm, newKey);
         Context.Policies.Set <IBuildKeyMappingPolicy>(new BuildKeyMappingPolicy(newKey), key);
         lm.Scope.Disposed += (o, de) =>
         {
             Context.Policies.Clear <ILifetimePolicy>(newKey);
             Context.Policies.Clear <IBuildKeyMappingPolicy>(key);
         };
     }
 }
コード例 #7
0
        /// <summary>
        /// Called when item is saved
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public void OnItemSaved(object sender, EventArgs args)
        {
            Assert.ArgumentNotNull(sender, "sender");
            Assert.ArgumentNotNull(args, "args");

            Item item = Event.ExtractParameter(args, 0) as Item;

            if (item == null)
            {
                return;
            }

            Item parent = item.Parent;

            if (parent == null)
            {
                return;
            }

            if (!parent.TemplateID.ToString().Equals(this.settingsRootTemplateId))
            {
                return;
            }

            Log.Info(string.Concat("RefreshSettingsEventHandler clearing site settings caches for item: (", item.Paths.FullPath, ")."), this);

            string siteName = SiteUtils.GetSiteByItem(item);

            if (string.IsNullOrEmpty(siteName))
            {
                return;
            }

            string entityName = string.Format("{0}_{1}", siteName, item.Database.Name);

            RegisterInstanceEventArgs arg = QueryableContainerExtension.Instances.FirstOrDefault(e => e.Instance != null && e.Instance is IEntity &&
                                                                                                 string.Equals(e.Name, entityName, StringComparison.OrdinalIgnoreCase) && ((IEntity)e.Instance).Alias.Equals(item.ID.ToString()));

            if (arg != null)
            {
                QueryableContainerExtension.Instances.Remove(arg);
            }
        }
コード例 #8
0
        private void OnNewInstance(object sender, RegisterInstanceEventArgs e)
        {
            HashSet <string> names;
            string           name = string.IsNullOrEmpty(e.Name) ? string.Empty : e.Name;

            if (!registeredTypes.TryGetValue(e.RegisteredType, out names))
            { //  not found, so add it
                registeredTypes.Add(e.RegisteredType, new HashSet <string> {
                    name
                });
            }
            else
            { //  already added type, so add name
                if (name == String.Empty && names.Contains(name))
                {
                    //default instance is already registered, let's give it a name so we can use ResolveAll() like it works in all other ioc containers
                    name = e.Name = Guid.NewGuid().ToString();
                }
                names.Add(name);
            }
        }
コード例 #9
0
 public InstanceRegisterEventArgs(RegisterInstanceEventArgs e, bool isDuplicated)
     : this(e.RegisteredType, e.Instance, e.Name, e.LifetimeManager, isDuplicated)
 {
 }
コード例 #10
0
 private void RegisterInstance(object sender, RegisterInstanceEventArgs e)
 {
     Register(e.RegisteredType.TypeHandle, e.Name);
 }
コード例 #11
0
 private void OnNewInstance(object sender, RegisterInstanceEventArgs e)
 {
     Register(e.Name, e.RegisteredType);
 }
コード例 #12
0
 private void Context_RegisteringInstance(object sender, RegisterInstanceEventArgs e)
 {
     SetInterceptorFor(e.RegisteredType, e.Instance.GetType());
 }
コード例 #13
0
 /// <summary>
 /// Handles the RegisteringInstance event of the Context control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="Microsoft.Practices.Unity.RegisterInstanceEventArgs"/> instance containing the event data.</param>
 protected virtual void ContextRegisteringInstance(object sender, RegisterInstanceEventArgs e)
 {
     Instances.Add(e);
 }
コード例 #14
0
        /// <summary>
        /// Contexts the on registering instance.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RegisterInstanceEventArgs" /> instance containing the event data.</param>
        private void ContextOnRegisteringInstance([CanBeNull] object sender, [NotNull] RegisterInstanceEventArgs e)
        {
            Assert.ArgumentNotNull(e, "e");

            this.AddRegistrationToDictionaries(e.RegisteredType, e.Name);
        }
コード例 #15
0
 void Context_RegisteringInstance(object sender, RegisterInstanceEventArgs e)
 {
     _logger.Log(String.Format("REG INSTANCE {0}", e.Instance.GetType().Name), Category.Debug, Priority.None);
 }