Example #1
0
        public void TestGetAllWhenNoImplementations()
        {
            context.ExpectBeginGetAll(type);
            abstractionConfigurationCollection.ExpectGet(type, abstractionConfiguration);

            var implementationConfiguration = new IImplementationConfiguration[0];

            abstractionConfiguration.ExpectGetImplementations(implementationConfiguration);
            context.ExpectEndGetAll(type);
            CollectionAssert.IsEmpty(internalContainer.GetAll(type, context));
        }
Example #2
0
        public AutoAbstractionConfiguration(Type abstractionType,
                                            IAbstractionsCollection abstractionsCollection,
                                            IImplementationConfigurationCache implementationConfigurationCache)
        {
            var abstraction = abstractionsCollection.Get(abstractionType);

            IImplementation[] implementations = abstraction.GetImplementations();
            implementationConfigurations = new IImplementationConfiguration[implementations.Length];
            for (int i = 0; i < implementations.Length; i++)
            {
                implementationConfigurations[i] = implementationConfigurationCache.GetOrCreate(implementations[i]);
            }
        }
 public InstanceAbstractionConfiguration(IClassWrapperCreator classWrapperCreator, Type abstractionType, object[] instances)
 {
     if (instances == null || instances.Length == 0)
     {
         throw new ArgumentException("instances");
     }
     implementationConfigurations = new IImplementationConfiguration[instances.Length];
     for (var i = 0; i < implementationConfigurations.Length; i++)
     {
         var type = instances[i].GetType();
         if (!abstractionType.IsAssignableFrom(type))
         {
             throw new ArgumentException($"Instances of type {type} cannot be used as abstraction of type {abstractionType}");
         }
         implementationConfigurations[i] = new InstanceImplementationConfiguration(classWrapperCreator, instances[i]);
     }
 }
Example #4
0
 public object Get(Type type, IInjectionContext context)
 {
     try
     {
         context.BeginGet(type);
         IImplementationConfiguration configuration = GetSingleImplementation(type);
         return(UnWrap(type, configuration.GetOrCreateInstance(context, creationContext)));
     }
     catch (Exception)
     {
         context.Crash();
         throw;
     }
     finally
     {
         context.EndGet(type);
     }
 }
Example #5
0
 public InstanceAbstractionConfiguration(IClassWrapperCreator classWrapperCreator, Type abstractionType, object[] instances)
 {
     if (instances == null || instances.Length == 0)
     {
         throw new ArgumentException("instances");
     }
     implementationConfigurations = new IImplementationConfiguration[instances.Length];
     for (int i = 0; i < implementationConfigurations.Length; i++)
     {
         Type type = instances[i].GetType();
         if (!abstractionType.IsAssignableFrom(type))
         {
             throw new ArgumentException("Заданная реализация на являются объектами типа " + abstractionType +
                                         " (реальный тип " + type + ")");
         }
         implementationConfigurations[i] = new InstanceImplementationConfiguration(classWrapperCreator, instances[i]);
     }
 }
        public void TestCacheWorks()
        {
            var implementation = new Implementation(typeof(int));
            IImplementationConfiguration cfg1 = implementationCache.GetOrCreate(implementation);

            Assert.That(cfg1, Is.InstanceOf <AutoImplementationConfiguration>());
            Assert.AreEqual(typeof(int), cfg1.ObjectType);

            Assert.AreSame(cfg1, implementationCache.GetOrCreate(implementation));

            var implementation2 = new Implementation(typeof(long));
            IImplementationConfiguration cfg2 = implementationCache.GetOrCreate(implementation2);

            Assert.AreNotEqual(cfg1, cfg2);

            Assert.AreSame(cfg1, implementationCache.GetOrCreate(implementation));
            Assert.AreSame(cfg2, implementationCache.GetOrCreate(implementation2));
        }
Example #7
0
 private object CreateImpl(Type abstractionType, IInjectionContext context,
                           Type[] argumentTypes, params object[] args)
 {
     try
     {
         context.BeginCreate(abstractionType);
         IImplementationConfiguration configuration = GetSingleImplementation(abstractionType);
         IClassFactory factory = configuration.GetFactory(argumentTypes, creationContext);
         return(UnWrap(abstractionType, factory.Create(context, args)));
     }
     catch (Exception)
     {
         context.Crash();
         throw;
     }
     finally
     {
         context.EndCreate(abstractionType);
     }
 }
 public IImplementorInstance Create(OutputPath output, IImplementationConfiguration configuration)
 {
     return new FPGAImplementorInstance(this, output, configuration);
 }
 public FPGAImplementorInstance(FPGAImplementor implementor, OutputPath output, IImplementationConfiguration config)
 {
     Implementor = implementor;
     OutputLocation = output;
     Configuration = config;
 }