예제 #1
0
        private EvaluatorSettings(
            [Parameter(typeof(ApplicationIdentifier))] string applicationId,
            [Parameter(typeof(EvaluatorIdentifier))] string evaluatorId,
            [Parameter(typeof(EvaluatorHeartbeatPeriodInMs))] int heartbeatPeriodInMs,
            [Parameter(typeof(HeartbeatMaxRetry))] int maxHeartbeatRetries,
            [Parameter(typeof(RootContextConfiguration))] string rootContextConfigString,
            RuntimeClock clock,
            IRemoteManagerFactory remoteManagerFactory,
            REEFMessageCodec reefMessageCodec,
            IInjector injector)
        {
            _injector = injector;
            _applicationId = applicationId;
            _evaluatorId = evaluatorId;
            _heartBeatPeriodInMs = heartbeatPeriodInMs;
            _maxHeartbeatRetries = maxHeartbeatRetries;
            _clock = clock;

            if (string.IsNullOrWhiteSpace(rootContextConfigString))
            {
                Utilities.Diagnostics.Exceptions.Throw(
                    new ArgumentException("empty or null rootContextConfigString"), Logger);
            }
            _rootContextConfig = new ContextConfiguration(rootContextConfigString);
            _rootTaskConfiguration = CreateTaskConfiguration();
            _rootServiceConfiguration = CreateRootServiceConfiguration();

            _remoteManager = remoteManagerFactory.GetInstance(reefMessageCodec);
            _operationState = EvaluatorOperationState.OPERATIONAL;
        }
		/*============================================================================*/
		/* Constructor                                                                */
		/*============================================================================*/

		/**
		 * @private
		 */
		public ModuleConnector(IContext context)
		{
			IInjector injector= context.injector;
			_rootInjector = GetRootInjector(injector);
			_localDispatcher = injector.GetInstance(typeof(IEventDispatcher)) as IEventDispatcher;
			context.WhenDestroying(Destroy);
		}
예제 #3
0
        public ContextRuntime(
            string id,
            IInjector serviceInjector,
            IConfiguration contextConfiguration)
        {
            // This should only be used at the root context to support backward compatibility.
            LOGGER.Log(Level.Info, "Instantiating root context");
            _contextLifeCycle = new ContextLifeCycle(id);
            _serviceInjector = serviceInjector;
            _parentContext = Optional<ContextRuntime>.Empty();
            try
            {
                _contextInjector = serviceInjector.ForkInjector();
            }
            catch (Exception e)
            {
                Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);

                Optional<string> parentId = ParentContext.IsPresent() ?
                    Optional<string>.Of(ParentContext.Value.Id) :
                    Optional<string>.Empty();
                ContextClientCodeException ex = new ContextClientCodeException(ContextClientCodeException.GetId(contextConfiguration), parentId, "Unable to spawn context", e);

                Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
            }

            // Trigger the context start events on contextInjector.
            _contextLifeCycle.Start();
        }
		/*============================================================================*/
		/* Public Functions                                                           */
		/*============================================================================*/

		public void Process(object view, Type type, IInjector injector)
		{
			if(!_injectedObjects.ContainsKey(view))
			{
				InjectAndRemember(view, injector);
			}
		}
		public void Setup()
		{
			injector = new robotlegs.bender.framework.impl.RobotlegsInjector();
			viewProcessorFactory = new ViewProcessorFactory(injector);
			trackingProcessor = new TrackingProcessor();
			view = new object();
		}
예제 #6
0
		public static bool Approve(IInjector injector, IEnumerable<object> guards)
		{
			object guardInstance;

			foreach (object guard in guards)
			{
				if (guard is Func<bool>)
				{
					if ((guard as Func<bool>)())
						continue;
					return false;
				}
				if (guard is Type)
				{
					if (injector != null)
						guardInstance = injector.InstantiateUnmapped(guard as Type);
					else
						guardInstance = Activator.CreateInstance(guard as Type);
				}
				else
					guardInstance = guard;

				MethodInfo approveMethod = guardInstance.GetType().GetMethod("Approve");
				if (approveMethod != null)
				{
					if ((bool)approveMethod.Invoke (guardInstance, null) == false)
						return false;
				}
				else
				{
					throw(new Exception (String.Format("Guard {0} is not a valid guard. It doesn't have the method 'Approve'", guardInstance)));
				}
			}
			return true;
		}
예제 #7
0
        public GroupCommClient(
            [Parameter(typeof(GroupCommConfigurationOptions.SerializedGroupConfigs))] ISet<string> groupConfigs,
            [Parameter(typeof(TaskConfigurationOptions.Identifier))] string taskId,
            StreamingNetworkService<GeneralGroupCommunicationMessage> networkService,
            AvroConfigurationSerializer configSerializer,
            IInjector injector)
        {
            _commGroups = new Dictionary<string, ICommunicationGroupClientInternal>();
            _networkService = networkService;

            foreach (string serializedGroupConfig in groupConfigs)
            {
                IConfiguration groupConfig = configSerializer.FromString(serializedGroupConfig);
                IInjector groupInjector = injector.ForkInjector(groupConfig);
                var commGroupClient = (ICommunicationGroupClientInternal)groupInjector.GetInstance<ICommunicationGroupClient>();
                _commGroups[commGroupClient.GroupName] = commGroupClient;
            }

            networkService.Register(new StringIdentifier(taskId));

            foreach (var group in _commGroups.Values)
            {
               group.WaitingForRegistration();
            }
        }
예제 #8
0
        /// <summary>
        /// Create a new ContextRuntime.
        /// </summary>
        /// <param name="serviceInjector"></param>
        /// <param name="contextConfiguration">the Configuration for this context.</param>
        /// <param name="parentContext"></param>
        public ContextRuntime(
                IInjector serviceInjector,
                IConfiguration contextConfiguration,
                Optional<ContextRuntime> parentContext)
        {
            ContextConfiguration config = contextConfiguration as ContextConfiguration;
            if (config == null)
            {
                var e = new ArgumentException("contextConfiguration is not of type ContextConfiguration");
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
            }
            _contextLifeCycle = new ContextLifeCycle(config.Id);
            _serviceInjector = serviceInjector;
            _parentContext = parentContext;
            try
            {
                _contextInjector = serviceInjector.ForkInjector();
            }
            catch (Exception e)
            {
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);

                Optional<string> parentId = ParentContext.IsPresent() ?
                    Optional<string>.Of(ParentContext.Value.Id) :
                    Optional<string>.Empty();
                ContextClientCodeException ex = new ContextClientCodeException(ContextClientCodeException.GetId(contextConfiguration), parentId, "Unable to spawn context", e);
                
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
            }
            // Trigger the context start events on contextInjector.
            _contextLifeCycle.Start();
        }
		/*============================================================================*/
		/* Public Functions                                                           */
		/*============================================================================*/

		public void Extend(IContext context)
		{
			_injector = context.injector;
			_logger = context.GetLogger(this);
			context.AfterInitializing (BeforeInitializing);
			context.AddConfigHandler(new InstanceOfMatcher (typeof(IContextView)), AddContextView);
		}
예제 #10
0
		public static void Apply(IInjector injector, IEnumerable<object> hooks)
		{
			object hookInstance;

			foreach (object hook in hooks)
			{
				if (hook is Action)
				{
					(hook as Action)();
					continue;
				}
				if (hook is Type)
				{
					if (injector != null)
						hookInstance = injector.InstantiateUnmapped(hook as Type);
					else
						hookInstance = Activator.CreateInstance(hook as Type);
				}
				else
					hookInstance = hook;

				MethodInfo hookMethod = hookInstance.GetType().GetMethod("Hook");
				if (hookMethod != null)
					hookMethod.Invoke (hookInstance, null);
				else
					throw new Exception ("Invalid hook to apply");
			}
		}
		public void before()
		{
			context = new Context();
			injector = context.injector;
			injector.Map<IDirectCommandMap>().ToType<DirectCommandMap>();
			subject = injector.GetInstance<IDirectCommandMap>() as DirectCommandMap;
		}
		public void Setup()
		{
			injector = new RobotlegsInjector();
			viewInjector = new ViewInjectionProcessor();
			injectionValue = MapSpriteForInjection();
			view = new ViewWithInjection();
		}
		public void Setup()
		{
			injector = new RobotlegsInjector();
			manager = new MediatorManager();
			container = new SupportView ();
			container.AddThisView();
			factory = new Mock<IMediatorFactory> ();
		}
		/*============================================================================*/
		/* Public Functions                                                           */
		/*============================================================================*/

		public void Extend(IContext context)
		{
			context.BeforeInitializing(BeforeInitializing)
				.BeforeDestroying(BeforeDestroying)
				.WhenDestroying(WhenDestroying);
			_injector = context.injector;
			_injector.Map (typeof(IMediatorMap)).ToSingleton (typeof(MediatorMap));
		}
예제 #15
0
 protected override void OnCreate(Bundle savedInstanceState)
 {
     base.OnCreate(savedInstanceState);
     Injector = GetInjector();
     Injector.InjectStrings(this);
     Injector.InjectExtras(this);
     Injector.InjectFromContainer(this, ((CalibrateApplication)Application).Container);
 }
		public void SetUp()
		{
			Context context = new Context();
			injector = context.injector;
			mediatorMap = new MediatorMap(context);
			mediatorWatcher = new MediatorWatcher();
			injector.Map(typeof(MediatorWatcher)).ToValue(mediatorWatcher);
		}
 //---------------------------------------------------------------------
 // Constructor
 //---------------------------------------------------------------------
 /**
  * Creates a new <code>ViewMap</code> object
  *
  * @param contextView The root view node of the context. The map will listen for ADDED_TO_STAGE events on this node
  * @param injector An <code>IInjector</code> to use for this context
  */
 public ViewMap( FrameworkElement contextView, IInjector injector )
     : base(contextView, injector)
 {
     // mappings - if you can do it with fewer dictionaries you get a prize
     this.mappedPackages = new List<string>();
     this.mappedTypes = new Dictionary<Type,Type>();
     this.injectedViews = new Dictionary<FrameworkElement,bool>(); //Warning was marked as weak
 }
 //---------------------------------------------------------------------
 //  Constructor
 //---------------------------------------------------------------------
 /**
  * Creates a new <code>CommandMap</code> object
  *
  * @param eventDispatcher The <code>IEventDispatcher</code> to listen to
  * @param injector An <code>IInjector</code> to use for this context
  * @param reflector An <code>IReflector</code> to use for this context
  */
 public CommandMap( IEventDispatcher eventDispatcher, IInjector injector, IReflector reflector )
 {
     this.eventDispatcher = eventDispatcher;
     this.injector = injector;
     this.reflector = reflector;
     this.eventTypeMap = new Dictionary<string,Dictionary<Type, Dictionary<Type, Action<Event>>>>();
     this.verifiedCommandClasses = new Dictionary<Type,bool>();
 }
		/*============================================================================*/
		/* Constructor                                                                */
		/*============================================================================*/

		public EventCommandTrigger (IInjector injector, IEventDispatcher dispatcher, Enum type, Type eventClass = null, IEnumerable<CommandMappingList.Processor> processors = null, ILogger logger = null)
		{
			_dispatcher = dispatcher;
			_type = type;
			_eventClass = eventClass;
			_mappings = new CommandMappingList(this, processors, logger);
			_executor = new CommandExecutor(injector, _mappings.RemoveMapping);
		}
		public void Unprocess(object view, Type type, IInjector injector)
 		{
			if (_createdMediatorsByView.ContainsKey(view))
			{
				DestroyMediator(_createdMediatorsByView[view]);
				_createdMediatorsByView.Remove(view);
			}
 		}
		public void Extend (IContext context)
		{
			_injector = context.injector;

			_parentFinder = new SupportParentFinder();
			_injector.Map(typeof(IParentFinder)).ToValue(_parentFinder);
			context.BeforeInitializing(BeforeInitializing);
		}
		public void Setup()
		{
			Dictionary<string,Type> config = new Dictionary<string, Type> ();
			config.Add ("intValue", typeof(int));
			config.Add ("stringValue", typeof(string));
			instance = new FastPropertyInjector(config);
			injector = new RobotlegsInjector();
		}
		/*============================================================================*/
		/* Constructor                                                                */
		/*============================================================================*/

		public MediatorFactory (IInjector injector)
		{
			_injector = injector;
			_manager = injector.HasMapping (typeof(IMediatorManager)) 
				? injector.GetInstance (typeof(IMediatorManager)) as IMediatorManager
				: new MediatorManager ();
			_manager.ViewRemoved += RemoveMediators;
		}
예제 #24
0
 public RootContextLauncher(string id, IConfiguration contextConfiguration,
     Optional<ServiceConfiguration> rootServiceConfig, Optional<TaskConfiguration> rootTaskConfig)
 {
     Id = id;
     _rootContextConfiguration = contextConfiguration;
     _rootServiceInjector = InjectServices(rootServiceConfig);
     RootTaskConfig = rootTaskConfig;
 }
		public void Setup()
		{
			injector = new RobotlegsInjector();
			instance = new ViewProcessorMap(new ViewProcessorFactory(injector));

			mediatorWatcher = new MediatorWatcher();
			injector.Map(typeof(MediatorWatcher)).ToValue(mediatorWatcher);
			matchingView = new SupportView();
		}
예제 #26
0
 public RootContextLauncher(string id, IConfiguration contextConfiguration,
     Optional<ServiceConfiguration> rootServiceConfig, Optional<IConfiguration> rootTaskConfig, IHeartBeatManager heartbeatManager)
 {
     Id = id;
     _rootContextConfiguration = contextConfiguration;
     _rootServiceInjector = InjectServices(rootServiceConfig);
     _rootServiceInjector.BindVolatileInstance(GenericType<IHeartBeatManager>.Class, heartbeatManager);
     RootTaskConfig = rootTaskConfig;
 }
		/*============================================================================*/
		/* Public Functions                                                           */
		/*============================================================================*/

		public void Extend(IContext context)
		{
			context.BeforeInitializing(BeforeInitializing);
			context.BeforeDestroying(BeforeDestroying);
			context.WhenDestroying(WhenDestroying);
			_injector = context.injector;
			_injector.Map(typeof(IViewProcessorFactory)).ToValue(new ViewProcessorFactory(_injector.CreateChild()));
			_injector.Map(typeof(IViewProcessorMap)).ToSingleton(typeof(ViewProcessorMap));
		}
		public void before()
		{
			reportedExecutions = new List<object>();
			IContext context = new Context();
			injector = context.injector;
			injector.Map(typeof(Action<object>), "ReportingFunction").ToValue((Action<object>)reportingFunction);
			dispatcher = new EventDispatcher();
			subject = new EventCommandMap(context, dispatcher);
		}
		/*============================================================================*/
		/* Public Functions                                                           */
		/*============================================================================*/

		public void Extend (IContext context)
		{
			_injector = context.injector;

			_singletonFactory = new SingletonFactory (_injector);

			context.BeforeInitializing (BeforeInitializing);
			context.BeforeDestroying(BeforeDestroying);
		}
        //---------------------------------------------------------------------
        // Constructor
        //---------------------------------------------------------------------
        /**
         * Creates a new <code>ViewMap</code> object
         *
         * @param contextView The root view node of the context. The map will listen for ADDED_TO_STAGE events on this node
         * @param injector An <code>IInjector</code> to use for this context
         */
        public ViewMapBase( FrameworkElement contextView, IInjector injector )
        {
            this.injector = injector;

            // change this at your peril lest ye understand the problem and have a better solution
            this.useCapture = true;

            // this must come last, see the setter
            this.ContextView = contextView;
        }
예제 #31
0
 internal LSystemStrategy(IInjector <TerrainInfo> terrainInjector, int rewritesCount = 6) : base(terrainInjector)
 {
     RewritesCount = rewritesCount;
 }
예제 #32
0
 public static void InjectMember(this IInjector source, object target, IInjectMember injectMember, IBuilderValue[] values)
 {
     source.InjectMembers(target, new IInjectMember[] { injectMember }, values);
 }
 public FindComponentRegistration(
     Type implementationType,
     IReadOnlyList <Type> interfaceTypes,
     IReadOnlyList <IInjectParameter> parameters,
     IInjector injector,
     in Scene scene,
예제 #34
0
 public static bool IsValueRegistered(this IInjector source, Type interfaceType)
 {
     return(source.IsValueRegistered(interfaceType, null));
 }
예제 #35
0
        public static IInjector CreateChild(this IInjector source)
        {
            var o = source.CreateChild(null);

            return(o);
        }
예제 #36
0
        public override IChildContainerAdapter CreateChildContainerAdapter()
        {
            IInjector injector = this.container.CreateChild();

            return(new MugenChildContainerAdapter(injector));
        }
예제 #37
0
 public static IInjector RegisterValue <TInterface>(this IInjector source, string name, TInterface value, ILifetime lifetime = null)
 {
     return(source.RegisterValue(typeof(TInterface), name, value, lifetime));
 }
예제 #38
0
 public static bool IsValueRegistered <TInterface>(this IInjector source, string name = null)
 {
     return(source.IsValueRegistered(typeof(TInterface), name));
 }
예제 #39
0
 public static void Inject(this IInjector source, object target)
 {
     source.Inject(target, null);
 }
예제 #40
0
 public static void Inject(this IInjector source, object target, IInjectMember[] injectMembers)
 {
     source.InjectMembers(target, injectMembers, null);
 }
예제 #41
0
 public MugenChildContainerAdapter(IInjector injector)
 {
     this.injector = injector;
 }
예제 #42
0
 public static IInjector RegisterProxy(this IInjector source, Type interfaceType, string name, Type proxyType)
 {
     return(source.RegisterProxy(interfaceType, name, proxyType, null));
 }
예제 #43
0
 public static bool TryGetValue(this IInjector source, Type type, string name, out object value)
 {
     return(source.TryGetValue(type, name, null, out value));
 }
예제 #44
0
 public static bool TryGetValue <T>(this IInjector source, out T value)
 {
     return(source.TryGetValue <T>(null, out value));
 }
예제 #45
0
 public static void RegisterValue(this IInjector source, Type interfaceType, object value, ILifetime lifetime = null)
 {
     source.RegisterValue(interfaceType, null, value, lifetime);
 }
예제 #46
0
 public static object Resolve(this IInjector source, Type targetType, string name = null)
 {
     return(source.Resolve(targetType, name, null));
 }
예제 #47
0
 public static IInjector RegisterType(this IInjector source, Type interfaceType, Type targetType, params IInjectMember[] injectMembers)
 {
     return(source.RegisterType(interfaceType, null, targetType, null, injectMembers));
 }
예제 #48
0
 public static IInjector RegisterProxy <TInterface, TProxy>(this IInjector source, string name = null, Type proxyServerType = null)
 {
     return(source.RegisterProxy(typeof(TInterface), name, typeof(TProxy), proxyServerType));
 }
예제 #49
0
        public async Task TestCommonStreamingCodecs()
        {
            IInjector                injector    = TangFactory.GetTang().NewInjector();
            IStreamingCodec <int>    intCodec    = injector.GetInstance <IntStreamingCodec>();
            IStreamingCodec <double> doubleCodec = injector.GetInstance <DoubleStreamingCodec>();
            IStreamingCodec <float>  floatCodec  = injector.GetInstance <FloatStreamingCodec>();

            IStreamingCodec <int[]>    intArrCodec    = injector.GetInstance <IntArrayStreamingCodec>();
            IStreamingCodec <double[]> doubleArrCodec = injector.GetInstance <DoubleArrayStreamingCodec>();
            IStreamingCodec <float[]>  floatArrCodec  = injector.GetInstance <FloatArrayStreamingCodec>();

            IStreamingCodec <string> stringCodec = injector.GetInstance <StringStreamingCodec>();

            CancellationToken token = new CancellationToken();

            int obj = 5;

            int[]    intArr    = { 1, 2 };
            double[] doubleArr = { 1, 2 };
            float[]  floatArr  = { 1, 2 };
            string   stringObj = "hello";

            var         stream = new MemoryStream();
            IDataWriter writer = new StreamDataWriter(stream);

            intCodec.Write(obj, writer);
            await intCodec.WriteAsync(obj + 1, writer, token);

            doubleCodec.Write(obj + 2, writer);
            await doubleCodec.WriteAsync(obj + 3, writer, token);

            floatCodec.Write(obj + 4, writer);
            await floatCodec.WriteAsync(obj + 5, writer, token);

            intArrCodec.Write(intArr, writer);
            await intArrCodec.WriteAsync(intArr, writer, token);

            doubleArrCodec.Write(doubleArr, writer);
            await doubleArrCodec.WriteAsync(doubleArr, writer, token);

            floatArrCodec.Write(floatArr, writer);
            await floatArrCodec.WriteAsync(floatArr, writer, token);

            stringCodec.Write(stringObj, writer);
            await stringCodec.WriteAsync(stringObj, writer, token);

            stream.Position = 0;
            IDataReader reader = new StreamDataReader(stream);
            int         res1   = intCodec.Read(reader);
            int         res2   = await intCodec.ReadAsync(reader, token);

            double res3 = doubleCodec.Read(reader);
            double res4 = await doubleCodec.ReadAsync(reader, token);

            float res5 = floatCodec.Read(reader);
            float res6 = await floatCodec.ReadAsync(reader, token);

            int[] resArr1 = intArrCodec.Read(reader);
            int[] resArr2 = await intArrCodec.ReadAsync(reader, token);

            double[] resArr3 = doubleArrCodec.Read(reader);
            double[] resArr4 = await doubleArrCodec.ReadAsync(reader, token);

            float[] resArr5 = floatArrCodec.Read(reader);
            float[] resArr6 = await floatArrCodec.ReadAsync(reader, token);

            string resArr7 = stringCodec.Read(reader);
            string resArr8 = await stringCodec.ReadAsync(reader, token);

            Assert.AreEqual(obj, res1);
            Assert.AreEqual(obj + 1, res2);
            Assert.AreEqual(obj + 2, res3);
            Assert.AreEqual(obj + 3, res4);
            Assert.AreEqual(obj + 4, res5);
            Assert.AreEqual(obj + 5, res6);
            Assert.AreEqual(stringObj, resArr7);
            Assert.AreEqual(stringObj, resArr8);

            for (int i = 0; i < intArr.Length; i++)
            {
                Assert.AreEqual(intArr[i], resArr1[i]);
                Assert.AreEqual(intArr[i], resArr2[i]);
            }

            for (int i = 0; i < doubleArr.Length; i++)
            {
                Assert.AreEqual(doubleArr[i], resArr3[i]);
                Assert.AreEqual(doubleArr[i], resArr4[i]);
            }

            for (int i = 0; i < floatArr.Length; i++)
            {
                Assert.AreEqual(floatArr[i], resArr5[i]);
                Assert.AreEqual(floatArr[i], resArr6[i]);
            }
        }
예제 #50
0
 public void TearDown()
 {
     instance        = null;
     injector        = null;
     mediatorWatcher = null;
 }
 public ExecutionInformation(IInjector injector)
 {
     dynamicObjects = injector;
     AddDynamicObject(this);
 }
예제 #52
0
 public static IInjector RegisterType <TInterface, TTarget>(this IInjector source, params IInjectMember[] injectMembers)
     where TTarget : TInterface
 {
     return(source.RegisterType(typeof(TInterface), null, typeof(TTarget), null, injectMembers));
 }
예제 #53
0
 public ChainedInjector(IInjector parent, T own)
 {
     ParentInjector = parent ?? throw new ArgumentNullException(nameof(parent));
     OwnInjector    = own ?? throw new ArgumentNullException(nameof(parent));
 }
예제 #54
0
        private static void Main()
        {
            //var configuration = new ConfigurationBuilder()
            //    .SetBasePath(Directory.GetCurrentDirectory())
            //    .AddJsonFile("appsettings.json")
            //    .Build();
            //var logger = new LoggerConfiguration()
            //    .ReadFrom.Configuration(configuration)
            //    .CreateLogger();

            //Juicer.AddLogging(new SerilogLoggerFactory(logger: logger));

            IInjector injector  = Juicer.CreateInjector(new TestModule().Override(new ModuleToOverride()));
            IInjector injector2 = injector.Get <IInjector>();
            IInjector injector3 = injector.CreateChildInjector();

            Console.WriteLine($"Injector was able to inject itself: {injector == injector2}.");

            Console.WriteLine();
            IService    service  = injector.Get <IService>();
            ServiceImpl service2 = injector.Get <ServiceImpl>();
            IService    service3 = injector3.Get <IService>();

            service.DoThing();
            Console.WriteLine($"Same instance of service when using untargeted vs targeted binding: {service == service2}.");
            Console.WriteLine($"Same instance of service retrieved from the child injector: {service == service3}");

            Console.WriteLine();
            Console.WriteLine($"Number from IService: {service.GetNumber()}");

            Console.WriteLine();
            HashSet <IMultiImplService> services = injector.Get <HashSet <IMultiImplService> >();

            Console.WriteLine($"Number of services created for IMultiImplService: {services?.Count}");

            Console.WriteLine();
            IOtherServiceFactory serviceFactory = injector.Get <IOtherServiceFactory>();
            IOtherService        otherService   = serviceFactory.CreateService(5);

            Console.WriteLine($"Factory service numbers: {otherService.GetNumber1()} | {otherService.GetNumber2()}");

            Console.WriteLine();
            NoInterfaceService noInterfaceService = injector.Get <NoInterfaceService>();

            noInterfaceService.PrintString();

            Console.WriteLine();
            Console.WriteLine($"Doubled Num1: {injector.Get<int>("DoubledNum1")}");

            Console.WriteLine();
            var externallyProvidedService = injector.Get <IExternallyProvidedService>();

            Console.WriteLine($"String from externally provided service: {externallyProvidedService.GetPrintString()}");
            Console.WriteLine($"Same instance of externally provided service received: {externallyProvidedService == injector.Get<IExternallyProvidedService>()}.");

            Console.WriteLine();
            var mappedServices = injector.Get <Dictionary <MappedServiceTypes, IMappedService> >();

            foreach (var type in Enum.GetValues(typeof(MappedServiceTypes)).Cast <MappedServiceTypes>())
            {
                var mappedService = mappedServices[type];
                mappedService.DoSomething();
            }
#if DEBUG
            Console.ReadLine();
#endif
        }
예제 #55
0
 public static object CreateInstance(this IInjector source, Type interfaceType, params IBuilderValue[] values)
 {
     return(source.CreateInstance(interfaceType, null, values));
 }
예제 #56
0
 public static void RegisterValue(this IInjector source, Type interfaceType, string name, object value)
 {
     source.RegisterValue(interfaceType, name, value, null);
 }
예제 #57
0
 public ExecutionInformation(IInjector parent) : base(parent, new BasicInjector())
 {
     this.AddModule(this);
 }
예제 #58
0
 public static TInterface Resolve <TInterface>(this IInjector source, IBuilderValue[] values)
 {
     return((TInterface)source.Resolve(typeof(TInterface), null, values));
 }