Пример #1
0
 private void OnRegister(object sender, RegisterEventArgs e)
 {
     Context.RegisterNamedType(e.TypeFrom ?? e.TypeTo, e.Name);
     if (e.TypeFrom != null)
     {
         if (e.TypeFrom.GetTypeInfo().IsGenericTypeDefinition && e.TypeTo.GetTypeInfo().IsGenericTypeDefinition)
         {
             Context.Policies.Set<IBuildKeyMappingPolicy>(
                 new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(e.TypeTo, e.Name)),
                 new NamedTypeBuildKey(e.TypeFrom, e.Name));
         }
         else
         {
             Context.Policies.Set<IBuildKeyMappingPolicy>(
                 new BuildKeyMappingPolicy(new NamedTypeBuildKey(e.TypeTo, e.Name)),
                 new NamedTypeBuildKey(e.TypeFrom, e.Name));
         }
     }
     if (e.LifetimeManager != null)
     {
         this.SetLifetimeManager(e.TypeTo, e.Name, e.LifetimeManager);
     }
 }
 private void OnRegister(object sender, RegisterEventArgs e)
 {
     registeredNames.RegisterType(e.TypeFrom ?? e.TypeTo, e.Name);
     if (e.TypeFrom != null)
     {
         if (e.TypeFrom.GetTypeInfo().IsGenericTypeDefinition&& e.TypeTo.GetTypeInfo().IsGenericTypeDefinition)
         {
             policies.Set <IBuildKeyMappingPolicy>(
                 new GenericTypeBuildKeyMappingPolicy(new NamedTypeBuildKey(e.TypeTo, e.Name)),
                 new NamedTypeBuildKey(e.TypeFrom, e.Name));
         }
         else
         {
             policies.Set <IBuildKeyMappingPolicy>(
                 new BuildKeyMappingPolicy(new NamedTypeBuildKey(e.TypeTo, e.Name)),
                 new NamedTypeBuildKey(e.TypeFrom, e.Name));
         }
     }
     if (e.LifetimeManager != null)
     {
         SetLifetimeManager(e.TypeFrom ?? e.TypeTo, e.Name, e.LifetimeManager);
     }
 }