Example #1
0
        public IGraphHandler CreateNewDocument(string packageId)
        {
            var graphHandler = m_InstanceCreator.CreateInstance <IGraphHandler>(new[] { new ConstructorArgument("packageId", packageId) });

            Documents.Add(graphHandler);

            return(graphHandler);
        }
Example #2
0
 public IResolutionEngine GetResolutionEngine(string package)
 {
     if (File.Exists(package))
     {
         var extension = Path.GetExtension(package);
         if (!string.IsNullOrEmpty(extension))
         {
             if (extension.EndsWith(".sln", StringComparison.CurrentCultureIgnoreCase))
             {
                 return(m_InstanceCreator.CreateInstance <ISolutionResolutionEngine>(new ConstructorArgument[] { }));
             }
             return(m_InstanceCreator.CreateInstance <IProjectResolutionEngine>(new ConstructorArgument[] { }));
         }
         return(null);
     }
     return(m_InstanceCreator.CreateInstance <INuGetResolutionEngine>(new ConstructorArgument[] { }));
 }
Example #3
0
 public object GetInstance(NancyContainer container, IInstanceCreator creator)
 {
     if (creator.Instance == null)
     {
         creator.Instance = creator.CreateInstance(container);
     }
     return creator.Instance;
 }
Example #4
0
        private T ValidateInstCreator <T>(IInstanceCreator instCreator)
        {
            var obj = instCreator.CreateInstance(new TestInjectionResolver());

            Assert.IsNotNull(obj);
            Assert.IsTrue(obj is T);

            return((T)obj);
        }
        public void CreateInstance_returns_exception_for_failing_method( )
        {
            IInstanceCreator creator = InstanceCreator.ForType <FailingClass>( );

            object result = creator.CreateInstance( );

            var actual = Assert.IsType <Exception>(result);

            Assert.Equal(typeof(FailingClass).FullName, actual.Message);
        }
Example #6
0
        /// <summary>
        /// Gets the instance from the Session, if available, otherwise creates a new
        /// instance and stores in the Session.
        /// </summary>
        /// <param name="creator">The creator (registration) to create a new instance.</param>
        /// <returns>The instance.</returns>
        public object GetInstance(IInstanceCreator creator)
        {
            object instance = Session[creator.Key];

            if (instance == null)
            {
                instance             = creator.CreateInstance(ContainerCaching.InstanceNotCachedInContainer);
                Session[creator.Key] = instance;
            }

            return(instance);
        }
Example #7
0
        public void ProvideInstance(IService service)
        {
            if (AutoValueChecker.Check(service))
            {
                service.Data.Instance = InstanceCreator.CreateInstance(service.Registration.TargetType);
            }

            else if (!AutoValueChecker.Check(service))
            {
                service.Data.Instance = null;
            }
        }
Example #8
0
        /// <summary>
        /// Gets the instance from cache, if available, otherwise creates a new
        /// instance and caches it.
        /// </summary>
        /// <param name="creator">The creator (registration) to create a new instance.</param>
        /// <returns>The instance.</returns>
        public object GetInstance(IInstanceCreator creator)
        {
            Cache cache = HttpRuntime.Cache;

            object instance = cache[creator.Key];

            if (instance == null)
            {
                instance = creator.CreateInstance(ContainerCaching.InstanceNotCachedInContainer);

                cache.Insert(creator.Key, instance, _dependencies, _absoluteExpiration,
                             _slidingExpiration, _priority, _onRemoveCallback);
            }

            return(instance);
        }
Example #9
0
        ICreatesWebDriver GetFactory(Type type)
        {
            object factory;

            try
            {
                factory = instanceCreator.CreateInstance(type);
            }
            catch (Exception)
            {
                // If there was a problem creating the factory just squelch the error and return null for no factory.
                return(null);
            }

            return(factory as ICreatesWebDriver);
        }
Example #10
0
        /// <summary>
        /// Gets an instance from the thread local storage, or creates a new instance if not found.
        /// </summary>
        /// <param name="creator">The IInstanceCreate to use to get the Key and create new if required.</param>
        /// <returns>The instance.</returns>
        public object GetInstance(IInstanceCreator creator)
        {
            object instance = null;

            // if it is a new thread then the localStorage needs to be initialized;
            if (localStorage == null)
            {
                localStorage = new Dictionary <string, object>();
            }

            if (!localStorage.TryGetValue(creator.Key, out instance))
            {
                instance = creator.CreateInstance(ContainerCaching.InstanceNotCachedInContainer);
                localStorage[creator.Key] = instance;
            }

            return(instance);
        }
 public void Initialize()
 {
     foreach (var plcSetting in setting.PlcSettings)
     {
         if (!plcSetting.IsMock)
         {
             var plc = instanceCreator.CreateInstance <BeckhoffPlc>(new[]
                                                                    { new ConstructorArgument("settings", plcSetting) });
             if (plc.Initialize())
             {
                 plcs.Add(plcSetting.Name, plc);
             }
             else
             {
                 Logger?.LogWarning("Unable to initialize Beckhoff: '{plcSetting}'", plcSetting);
             }
         }
         else
         {
             plcs.Add(plcSetting.Name, new MockPlc());
         }
     }
 }
 public IServiceFactory ProvideServiceFactory(Type @class)
 {
     return((IServiceFactory)InstanceCreator.CreateInstance(@class));
 }
 /// <summary>
 /// Gets a new instance.
 /// </summary>
 /// <param name="creator">The creator (registration) that can create an instance</param>
 /// <returns>The new instance.</returns>
 public object GetInstance(IInstanceCreator creator)
 {
     return(creator.CreateInstance(ContainerCaching.InstanceNotCachedInContainer));
 }
 /// <summary>
 /// Resolves the object held by the container
 /// </summary>
 /// <param name="resolver">Injection resolver to acquire parameters</param>
 /// <returns>Resolved instance of the object</returns>
 /// <exception cref="CommonIoCException">Can be raised when injections not found</exception>
 public sealed override object GetInstance(IInjectionResolver resolver)
 {
     return(_createInstanceObj.CreateInstance(resolver));
 }
 public static IMetadataReader GetReader(string rawFilePath)
 {
     return(ReaderCreator.CreateInstance(rawFilePath));
 }
Example #16
0
        /// <summary>
        /// Resolves the object held by the container
        /// </summary>
        /// <param name="resolver">Injection resolver to acquire parameters</param>
        /// <returns>Resolved instance of the object</returns>
        /// <exception cref="CommonIoCException">Can be raised when injections not found</exception>
        public sealed override object GetInstance(IInjectionResolver resolver)
        {
            TurboContract.Requires(resolver != null, conditionString: "resolver != null");

            return(_createInstanceObj.CreateInstance(resolver));
        }
                object IInstanceCreator.CreateInstance( )
                {
                    IInstanceCreator innerCreator = this.innerCreator_;

                    return(innerCreator.CreateInstance( ));
                }
Example #18
0
 public object GetInstance(NancyContainer container, IInstanceCreator creator)
 {
     return creator.CreateInstance(container);
 }