Exemplo n.º 1
0
        public override object GetInstance(IInstanceFactory factory, IResolver resolver)
        {
            if (!_threadLocalInstance.IsValueCreated)
                _threadLocalInstance.Value = factory.CreateInstance(resolver);

            return _threadLocalInstance.Value;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Construct an <see cref="InstanceManager"/>
        /// </summary>
        /// <param name="instanceFactory">The value of <see cref="instanceFactory"/></param>
        /// <param name="ioManager">The value of <paramref name="ioManager"/></param>
        /// <param name="databaseContextFactory">The value of <paramref name="databaseContextFactory"/></param>
        /// <param name="application">The value of <see cref="application"/></param>
        /// <param name="jobManager">The value of <see cref="jobManager"/></param>
        /// <param name="serverControl">The <see cref="IServerControl"/> for the <see cref="InstanceManager"/></param>
        /// <param name="logger">The value of <see cref="logger"/></param>
        public InstanceManager(IInstanceFactory instanceFactory, IIOManager ioManager, IDatabaseContextFactory databaseContextFactory, IApplication application, IJobManager jobManager, IServerControl serverControl, ILogger <InstanceManager> logger)
        {
            this.instanceFactory        = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
            this.ioManager              = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
            this.databaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
            this.application            = application ?? throw new ArgumentNullException(nameof(application));
            this.jobManager             = jobManager ?? throw new ArgumentNullException(nameof(jobManager));

            if (serverControl == null)
            {
                throw new ArgumentNullException(nameof(serverControl));
            }

            shutdownCancellationTokenSource = new CancellationTokenSource();
            var cancellationToken = shutdownCancellationTokenSource.Token;

            serverControl.RegisterForRestart(() =>
            {
                lock (this)
                    shutdownTasks.AddRange(instances.Select(x => x.Value.Chat.SendBroadcast("TGS: Restart requested...", cancellationToken)));
            });

            this.logger = logger ?? throw new ArgumentNullException(nameof(logger));

            instances     = new Dictionary <long, IInstance>();
            shutdownTasks = new List <Task>();
        }
Exemplo n.º 3
0
        static Mocked()
        {
            var stubFactoryCollection = new StubFactoryCollection();
            var moqBuilderFactory     = new MoqBuilderFactory(stubFactoryCollection);

            stubFactoryCollection.Append(new EmptyStringFactory());
            stubFactoryCollection.Append(new DefaultDateFactory());
            stubFactoryCollection.Append(new DefaultPrimitiveTypeFactory());
            stubFactoryCollection.Append(new NullableFactory());
            stubFactoryCollection.Append(new InterfaceStubFactory(moqBuilderFactory));
            stubFactoryCollection.Append(new TypeWithSingleParameterlessConstructorFactory(moqBuilderFactory));
            stubFactoryCollection.Append(new TypeWithSingleConstructorFactory(moqBuilderFactory, stubFactoryCollection));

            DefaultStubFactory         = stubFactoryCollection;
            DefaultDependenciesFactory = new StubDependenciesFactory(stubFactoryCollection);

            DefaultInstanceFactory = new InstanceFactoryCollection(
                new ConcreteInstanceFactory(),
                new AbstractClassFactory(moqBuilderFactory)
                );

            DefaultConstructorSelector = new ConstructorSelectorCollection(
                new ParameterlessConstructorSelector(),
                new SingleConstructorSelector()
                );

            DefaultMockedInstanceFactory = new MockedInstanceFactory(
                DefaultConstructorSelector,
                DefaultDependenciesFactory,
                DefaultInstanceFactory
                );
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="QueryficationEngine"/> class.
        /// </summary>
        /// <param name="propertyMetadataFactory">An implementation of the <see cref="IPropertyMetadataFactory"/> interface.</param>
        /// <param name="propertyReflectorSelector">An implementation of the <see cref="IPropertyReflectorSelector"/> interface.</param>
        /// <param name="instanceFactory">An implementation of the <see cref="IInstanceFactory"/> interface.</param>
        /// <param name="valueProcessorFactory">An implementation of the <see cref="IValueProcessorFactory"/> interface.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="propertyMetadataFactory"/>', '<paramref name="propertyReflectorSelector"/>', '<paramref name="instanceFactory"/>' and '<paramref name="valueProcessorFactory"/>' cannot be null. </exception>
        public QueryficationEngine(IPropertyMetadataFactory propertyMetadataFactory, IPropertyReflectorSelector propertyReflectorSelector, IInstanceFactory instanceFactory, IValueProcessorFactory valueProcessorFactory)
        {
            if (propertyMetadataFactory == null)
            {
                throw new ArgumentNullException(nameof(propertyMetadataFactory));
            }

            if (propertyReflectorSelector == null)
            {
                throw new ArgumentNullException(nameof(propertyReflectorSelector));
            }

            if (instanceFactory == null)
            {
                throw new ArgumentNullException(nameof(instanceFactory));
            }

            if (valueProcessorFactory == null)
            {
                throw new ArgumentNullException(nameof(valueProcessorFactory));
            }

            this.valueProcessorFactory     = valueProcessorFactory;
            this.propertyMetadataFactory   = propertyMetadataFactory;
            this.propertyReflectorSelector = propertyReflectorSelector;
            this.instanceFactory           = instanceFactory;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InstanceManager"/> class.
        /// </summary>
        /// <param name="instanceFactory">The value of <see cref="instanceFactory"/>.</param>
        /// <param name="ioManager">The value of <paramref name="ioManager"/>.</param>
        /// <param name="databaseContextFactory">The value of <paramref name="databaseContextFactory"/>.</param>
        /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/>.</param>
        /// <param name="jobManager">The value of <see cref="jobManager"/>.</param>
        /// <param name="serverControl">The value of <see cref="serverControl"/>.</param>
        /// <param name="systemIdentityFactory">The value of <see cref="systemIdentityFactory"/>.</param>
        /// <param name="asyncDelayer">The value of <see cref="asyncDelayer"/>.</param>
        /// <param name="serverPortProvider">The value of <see cref="serverPortProvider"/>.</param>
        /// <param name="swarmService">The value of <see cref="swarmService"/>.</param>
        /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/>.</param>
        /// <param name="swarmConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="swarmConfiguration"/>.</param>
        /// <param name="logger">The value of <see cref="logger"/>.</param>
        public InstanceManager(
            IInstanceFactory instanceFactory,
            IIOManager ioManager,
            IDatabaseContextFactory databaseContextFactory,
            IAssemblyInformationProvider assemblyInformationProvider,
            IJobManager jobManager,
            IServerControl serverControl,
            ISystemIdentityFactory systemIdentityFactory,
            IAsyncDelayer asyncDelayer,
            IServerPortProvider serverPortProvider,
            ISwarmService swarmService,
            IOptions <GeneralConfiguration> generalConfigurationOptions,
            IOptions <SwarmConfiguration> swarmConfigurationOptions,
            ILogger <InstanceManager> logger)
        {
            this.instanceFactory             = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
            this.ioManager                   = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
            this.databaseContextFactory      = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
            this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
            this.jobManager                  = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
            this.serverControl               = serverControl ?? throw new ArgumentNullException(nameof(serverControl));
            this.systemIdentityFactory       = systemIdentityFactory ?? throw new ArgumentNullException(nameof(systemIdentityFactory));
            this.asyncDelayer                = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
            this.serverPortProvider          = serverPortProvider ?? throw new ArgumentNullException(nameof(serverPortProvider));
            this.swarmService                = swarmService ?? throw new ArgumentNullException(nameof(swarmService));
            generalConfiguration             = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
            swarmConfiguration               = swarmConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(swarmConfigurationOptions));
            this.logger = logger ?? throw new ArgumentNullException(nameof(logger));

            instances      = new Dictionary <long, InstanceContainer>();
            bridgeHandlers = new Dictionary <string, IBridgeHandler>();
            readyTcs       = new TaskCompletionSource <object>();
            instanceStateChangeSemaphore = new SemaphoreSlim(1);
        }
Exemplo n.º 6
0
        public NavigationService(IInstanceFactory instanceFactory, ILifecycleService lifecycleService)
        {
            this.lifecycleService = lifecycleService;
            this.instanceFactory  = instanceFactory;

            this.frame = (Frame)Application.Current.MainWindow.FindName("Frame");
        }
Exemplo n.º 7
0
 private static QueryProvider CreateQueryProvider(IInstanceFactory instanceFactory)
 {
     return(new Mock <QueryProvider>(instanceFactory)
     {
         CallBase = true
     }.Object);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Construct an <see cref="InstanceManager"/>
        /// </summary>
        /// <param name="instanceFactory">The value of <see cref="instanceFactory"/></param>
        /// <param name="ioManager">The value of <paramref name="ioManager"/></param>
        /// <param name="databaseContextFactory">The value of <paramref name="databaseContextFactory"/></param>
        /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/></param>
        /// <param name="jobManager">The value of <see cref="jobManager"/></param>
        /// <param name="serverControl">The value of <see cref="serverControl"/></param>
        /// <param name="systemIdentityFactory">The value of <see cref="systemIdentityFactory"/>.</param>
        /// <param name="asyncDelayer">The value of <see cref="asyncDelayer"/>.</param>
        /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/>.</param>
        /// <param name="logger">The value of <see cref="logger"/></param>
        public InstanceManager(
            IInstanceFactory instanceFactory,
            IIOManager ioManager,
            IDatabaseContextFactory databaseContextFactory,
            IAssemblyInformationProvider assemblyInformationProvider,
            IJobManager jobManager,
            IServerControl serverControl,
            ISystemIdentityFactory systemIdentityFactory,
            IAsyncDelayer asyncDelayer,
            IOptions <GeneralConfiguration> generalConfigurationOptions,
            ILogger <InstanceManager> logger)
        {
            this.instanceFactory             = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
            this.ioManager                   = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
            this.databaseContextFactory      = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
            this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
            this.jobManager                  = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
            this.serverControl               = serverControl ?? throw new ArgumentNullException(nameof(serverControl));
            this.systemIdentityFactory       = systemIdentityFactory ?? throw new ArgumentNullException(nameof(systemIdentityFactory));
            this.asyncDelayer                = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
            generalConfiguration             = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
            this.logger = logger ?? throw new ArgumentNullException(nameof(logger));

            serverControl.RegisterForRestart(this);

            instances      = new Dictionary <long, IInstance>();
            bridgeHandlers = new Dictionary <string, IBridgeHandler>();
            readyTcs       = new TaskCompletionSource <object>();
        }
Exemplo n.º 9
0
 private static void UpdateInstance(IInstanceFactory nodeDesign, UAInstance nodeSet, IUANodeBase nodeContext, Action <TraceMessage> traceEvent)
 {
     nodeDesign.ModelingRule   = nodeContext.ModelingRule;
     nodeDesign.TypeDefinition = nodeContext.ExportBaseTypeBrowseName(false);
     //nodeSet.ParentNodeId - The NodeId of the Node that is the parent of the Node within the information model. This field is used to indicate
     //that a tight coupling exists between the Node and its parent (e.g. when the parent is deleted the child is deleted
     //as well). This information does not appear in the AddressSpace and is intended for use by design tools.
 }
 public InstanceFactoryBuilderStrategy(IInstanceFactory instanceFactory)
 {
     if (instanceFactory == null)
     {
         throw new ArgumentNullException("instanceFactory");
     }
     InstanceFactory = instanceFactory;
 }
Exemplo n.º 11
0
 public HtmlTemplateTransform(
     IInstanceFactory instanceFactory,
     IHtmlDocumentVistor htmlVisitor
     )
 {
     _instanceFactory = instanceFactory;
     _htmlVisitor     = htmlVisitor;
 }
Exemplo n.º 12
0
 public InstanceFactoryContainerExtension(IInstanceFactory instanceFactory)
 {
     if (instanceFactory == null)
     {
         throw new ArgumentNullException("instanceFactory");
     }
     InstanceFactory = instanceFactory;
 }
Exemplo n.º 13
0
        public NavigationService(RootNavigationPage navigationPage, ILifecycleService lifecycleService)
        {
            this.NavigationPage   = Application.Current.MainPage as RootNavigationPage;
            this.instanceFactory  = IocInstanceFactory.Default;
            this.lifecycleService = lifecycleService;

            this.NavigationPage.BackButtonPressedEvent += this.NavigationPageBackButtonPressedEvent;
        }
        private static void ConfigureBus(ContainerBuilder builder)
        {
            builder.Register(context =>
            {
                List <IInstanceFactory> instanceFactories = new List <IInstanceFactory>();

                var listoptions = context.Resolve <List <RabbitMqOptions> >();
                var tracer      = context.Resolve <ITracer>();

                if (listoptions != null)
                {
                    foreach (var item in listoptions)
                    {
                        IInstanceFactory instanceFactory = RawRabbit.Instantiation.RawRabbitFactory.CreateInstanceFactory(new RawRabbitOptions
                        {
                            DependencyInjection = ioc =>
                            {
                                ioc.AddSingleton(item as RabbitMqOptions);
                                ioc.AddSingleton(item as RawRabbitConfiguration);
                                ioc.AddSingleton <INamingConventions>(new CustomNamingConventions(item.Namespace));
                                ioc.AddSingleton(tracer);


                                ioc.AddSingleton <ITenant, Tenant>(provider =>
                                {
                                    Tenant tenant1   = new Tenant();
                                    tenant1.TenantId = item.VirtualHost;
                                    return(tenant1);
                                });

                                var tenant      = context.Resolve <ITenant>();
                                tenant.TenantId = item.VirtualHost;
                                //var dbContext = context.Resolve<IBaseDbContext>();
                                //dbContext.RabbitMqcnnSQL = item.VirtualHost;
                                //ioc.AddSingleton(dbContext);
                            },
                            Plugins = p => p
                                      .UseAttributeRouting()
                                      .UseRetryLater()
                                      .UpdateRetryInfo()
                                      .UseMessageContext <CorrelationContext>()
                                      .UseContextForwarding()
                                      .UseJaeger(tracer)
                        });

                        instanceFactories.Add(instanceFactory);
                    }
                }

                return(instanceFactories);
            }).SingleInstance();
            builder.Register(context =>
            {
                List <RawRabbit.IBusClient> busClients = new List <RawRabbit.IBusClient>();
                context.Resolve <List <IInstanceFactory> >().ForEach(x => busClients.Add(x.Create()));
                return(busClients);
            });
        }
Exemplo n.º 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LambdaExpressionInitializer"/> class.
        /// </summary>
        /// <param name="instanceFactory">The <see cref="IInstanceFactory"/>.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="instanceFactory"/>' cannot be null. </exception>
        public LambdaExpressionInitializer([NotNull] IInstanceFactory instanceFactory)
        {
            if (instanceFactory == null)
            {
                throw new ArgumentNullException(nameof(instanceFactory));
            }

            this.instanceFactory = instanceFactory;
        }
Exemplo n.º 16
0
        public void CanAddInstancesDirectlyToAnInstanceFactory()
        {
            IInstanceFactory factory = getISomethingFactory();

            factory.AddInstance(new ObjectInstance(_red).WithName("Red"));
            factory.AddInstance(new ObjectInstance(_blue).WithName("Blue"));

            factory.FindInstance("Red").ShouldNotBeNull();
        }
Exemplo n.º 17
0
        protected QueryProvider(IInstanceFactory instanceFactory)
        {
            if (instanceFactory == null)
            {
                throw new ArgumentNullException("instanceFactory");
            }

            this._instanceFactory = instanceFactory;
        }
Exemplo n.º 18
0
        public static T CreateInstance <T>([NotNull] this IInstanceFactory instanceFactory)
        {
            if (instanceFactory == null)
            {
                throw new ArgumentNullException(nameof(instanceFactory));
            }

            return(instanceFactory.CreateInstance <T>(typeof(T)));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Tries to create an instance of the supplied <see cref="Type"/>.
        /// </summary>
        /// <param name="instanceFactory">The <see cref="IInstanceFactory"/>.</param>
        /// <typeparam name="T">The <see cref="Type"/> from which an istance must be created.</typeparam>
        /// <param name="result"><c>Null</c> or an instance of the expected <see cref="Type"/>.</param>
        /// <returns><c>true</c> if the creation of the instance was successful; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="instanceFactory"/>' cannot be null. </exception>
        public static Boolean TryCreateInstance <T>([NotNull] this IInstanceFactory instanceFactory, [CanBeNull] out T result)
        {
            if (instanceFactory == null)
            {
                throw new ArgumentNullException(nameof(instanceFactory));
            }

            return(instanceFactory.TryCreateInstance(typeof(T), out result));
        }
Exemplo n.º 20
0
 public MockedInstanceFactory(
     IConstructorSelector constructorSelector,
     IDependenciesFactory dependenciesFactory,
     IInstanceFactory instanceFactory)
 {
     _dependenciesFactory = dependenciesFactory;
     _constructorSelector = constructorSelector;
     _instanceFactory     = instanceFactory;
 }
Exemplo n.º 21
0
 public DynamicBuilder(
     IInstanceFactory <T> instanceFactory = null,
     IPropertySetter propertySetter       = null,
     IMemberSelector memberSelector       = null)
 {
     InstanceFactory = instanceFactory ?? new ConstructorInstanceFactory <T>();
     PropertySetter  = propertySetter ?? new PropertySetter();
     MemberSelector  = memberSelector ?? new MemberSelector();
     _properties     = new ReadOnlyCollection <PropertyInfo>(MemberSelector.SelectProperties(typeof(T)).ToList());
 }
Exemplo n.º 22
0
 public SquiggleContextFactory(IInstanceFactory <PluginLoader> pluginLoaderFactory,
                               HistoryManager history,
                               MainWindow window,
                               string clientId)
 {
     this.pluginLoaderFactory = pluginLoaderFactory;
     this.history             = history;
     this.window   = window;
     this.clientId = clientId;
 }
Exemplo n.º 23
0
        static SerializationServices()
        {
            if (_assemblyLoader == null)
            {
                _assemblyLoader = new DefaultAssemblyLoader();
            }
            BindAssemblyLoader(_assemblyLoader);

            _factory = new DefaultInstanceFactory();
        }
Exemplo n.º 24
0
        public bool HasDefaultForPluginType(Type pluginType)
        {
            IInstanceFactory factory = ForType(pluginType);

            if (_profileManager.GetDefault(pluginType) != null)
            {
                return(true);
            }

            return(factory.AllInstances.Count() == 1);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Construct an <see cref="InstanceManager"/>
        /// </summary>
        /// <param name="instanceFactory">The value of <see cref="instanceFactory"/></param>
        /// <param name="ioManager">The value of <paramref name="ioManager"/></param>
        /// <param name="databaseContextFactory">The value of <paramref name="databaseContextFactory"/></param>
        /// <param name="application">The value of <see cref="application"/></param>
        /// <param name="jobManager">The value of <see cref="jobManager"/></param>
        /// <param name="logger">The value of <see cref="logger"/></param>
        public InstanceManager(IInstanceFactory instanceFactory, IIOManager ioManager, IDatabaseContextFactory databaseContextFactory, IApplication application, IJobManager jobManager, ILogger <InstanceManager> logger)
        {
            this.instanceFactory        = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
            this.ioManager              = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
            this.databaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
            this.application            = application ?? throw new ArgumentNullException(nameof(application));
            this.jobManager             = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
            this.logger = logger ?? throw new ArgumentNullException(nameof(logger));

            instances = new Dictionary <long, IInstance>();
        }
Exemplo n.º 26
0
        public NavigationService(IInstanceFactory instanceFactory, ILifecycleService lifecycleService)
        {
            this.instanceFactory  = instanceFactory;
            this.lifecycleService = lifecycleService;

            //SystemNavigationManager.GetForCurrentView().BackRequested += (s, o) =>
            //    {
            //        o.Handled = true;
            //        this.GoBack();
            //    };
        }
Exemplo n.º 27
0
        public void FindAPluginFamilyForAGenericTypeFromPluginTypeName()
        {
            Type        serviceType   = typeof(IService <string>);
            PluginGraph pluginGraph   = PluginGraph.BuildGraphFromAssembly(serviceType.Assembly);
            var         pipelineGraph = new PipelineGraph(pluginGraph);

            Type stringService = typeof(IService <string>);

            IInstanceFactory factory = pipelineGraph.ForType(stringService);

            Assert.AreEqual(stringService, factory.PluginType);
        }
Exemplo n.º 28
0
        /// <summary>
        ///     Adds the given factory to the value providers.
        /// </summary>
        /// <exception cref="ArgumentNullException">factory can not be null.</exception>
        /// <param name="factory">The factory to add.</param>
        /// <returns>Returns the modified create instance options.</returns>
        public IFactoryOptionsInconsistent <T> WithFactory(Func <IMemberInformation, Object> factory)
        {
            factory.ThrowIfNull(nameof(factory));

            // Create and add factory
            _currentFactory = new ExpressionInstanceFactory(factory);
            Factories.Add(_currentFactory);

            // Set target to factory
            _currentMemberSelectionTarget = MemberSelectionRuleTarget.Factory;

            return(this);
        }
Exemplo n.º 29
0
        public bool TryGetFactory(Type type, out IInstanceFactory factory)
        {
            CheckIsNotNull(nameof(type), type);

            bool found = _factories.TryGetValue(type, out factory);

            if (!found && _parent != null)
            {
                found = _parent.TryGetFactory(type, out factory);
            }

            return(found);
        }
Exemplo n.º 30
0
        public override object GetInstance(IInstanceFactory factory, IResolver resolver)
        {
            Cache cache = HttpRuntime.Cache;

            var instance = cache[_key];
            if (instance == null)
            {
                instance = factory.CreateInstance(resolver);
                cache.Insert(_key, instance, _dependency, _absoluteExpiration, _slidingExpiration, _itemPriority, _itemRemovedCallback);
            }

            return instance;
        }
Exemplo n.º 31
0
        public static T CreateInstance <T>(this IInstanceFactory instanceFactory, [NotNull] Type type)
        {
            if (instanceFactory == null)
            {
                throw new ArgumentNullException(nameof(instanceFactory));
            }

            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            return((T)instanceFactory.CreateInstance(type));
        }
Exemplo n.º 32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ValueProcessorFactory"/> class.
        /// </summary>
        /// <param name="valueProcessorRegistry">An implementation of the <see cref="ITypeValueProcessorRegistry"/> interface.</param>
        /// <param name="instanceFactory">An implementation of the <see cref="ITypeValueProcessorRegistry"/> interface.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="valueProcessorRegistry"/>' and '<paramref name="instanceFactory"/>' cannot be null. </exception>
        public ValueProcessorFactory([NotNull] ITypeValueProcessorRegistry valueProcessorRegistry, [NotNull] IInstanceFactory instanceFactory)
        {
            if (valueProcessorRegistry == null)
            {
                throw new ArgumentNullException(nameof(valueProcessorRegistry));
            }

            if (instanceFactory == null)
            {
                throw new ArgumentNullException(nameof(instanceFactory));
            }

            this.valueProcessorRegistry = valueProcessorRegistry;
            this.instanceFactory        = instanceFactory;
        }
Exemplo n.º 33
0
        public override object GetInstance(IInstanceFactory factory, IResolver resolver)
        {
            var session = Context.Session;

            // if run in Application_Start() Session will be null - just return new instance ?
            if (session == null)
                return factory.CreateInstance(resolver);

            object instance = session[_key];

            if (instance == null)
            {
                instance = factory.CreateInstance(resolver);
                session[_key] = instance;
            }

            return instance;
        }
Exemplo n.º 34
0
        public override object GetInstance(IInstanceFactory factory, IResolver resolver)
        {
            var context = Context;

            var instance = context.Items[_key];
            if (instance == null)
            {
                instance = factory.CreateInstance(resolver);
                context.Items[_key] = instance;

                if (_disposeOnEnd)
                    context.RegisterForDispose((IDisposable)instance);	// throws exception to make you aware that it doesnt implement IDisposable as expected
                                                                        // But should throw different Exception than InvalidCastException ? Fix test ?
                                                                        // Could make the check in Init instead ?
            }

            return instance;
        }
Exemplo n.º 35
0
 public InstanceBuilder(IInstanceFactory instanceFactory)
 {
     _instanceFactory = instanceFactory;
     _interceptors = new List<IInterceptor>();
     _lifetime = TransientLifetime.Instance;
 }
        public void SetUp()
        {
            factory = new InstanceFactory(typeof (IGateway));
            factory.AddInstance(new SmartInstance<DefaultGateway>());
            factory.AddInstance(new SmartInstance<DefaultGateway>());

            var lifecycle = MockRepository.GenerateMock<ILifecycle>();
            factory.Lifecycle = lifecycle;
            factory.MissingInstance = new SmartInstance<DefaultGateway>();

            clone = factory.Clone();
        }
 private static QueryProvider CreateQueryProvider(IInstanceFactory instanceFactory)
 {
     return new Mock<QueryProvider>(instanceFactory) {CallBase = true}.Object;
 }
Exemplo n.º 38
0
 public ObjectMapper(IInstanceFactory instanceFactory)
 {
     _instanceFactory = instanceFactory;
     _recordToPropertyMappers = new List<DataRecordToPropertyMapper>();
 }
 public InstanceFactoryBuilderStrategy(IInstanceFactory instanceFactory)
 {
     if (instanceFactory == null) { throw new ArgumentNullException("instanceFactory"); }
     InstanceFactory = instanceFactory;
 }
Exemplo n.º 40
0
 public Pipeline(List<IInterceptor> interceptors, IInstanceFactory instanceFactory, IContext context)
 {
     _interceptors = interceptors;
     _instanceFactory = instanceFactory;
     _context = context;
 }
 public HttpHostConfiguration SetInstanceFactory(IInstanceFactory factory)
 {
     this.InstanceFactory = factory;
     return this;
 }
Exemplo n.º 42
0
 public override object GetInstance(IInstanceFactory factory, IResolver resolver)
 {
     return factory.CreateInstance(resolver);
 }
 public QueryProvider(IInstanceFactory instanceFactory)
     : base(instanceFactory)
 {
 }
 public InstanceFactoryProvider(Type serviceType, IInstanceFactory instanceFactory)
 {
     this.serviceType = serviceType;
     this.instanceFactory = instanceFactory;
 }
Exemplo n.º 45
0
 public abstract object GetInstance(IInstanceFactory factory, IResolver resolver);