Exemplo n.º 1
0
        private IService CreateNewServiceInstance(Type serviceType)
        {
            IService service;

            if (serviceFactories.ContainsKey(serviceType))
            {
                Type factoryType = serviceFactories[serviceType];
                service = CreateServiceFromFactory(factoryType);
            }
            else
            {
                if (serviceType.IsSubclassOf(typeof(MonoBehaviour)))
                {
                    GameObject gameObject = new GameObject("[Service] " + serviceType);
                    gameObject.SetActive(false);
                    service = gameObject.AddComponent(serviceType) as IService;
                    dependencyInjector.InjectGameObject(gameObject);
                    gameObject.SetActive(true);
                }
                else
                {
                    service = dependencyInjector.CreateType(serviceType) as IService;
                }
            }

            InstantiatedServices.Add(serviceType, service);
            callbackModule.Add(service);

            return(service);
        }