<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace SceneJect.Common
{
	public class DefaultGameObjectFactory : IGameObjectFactory
	{
		/// <summary>
		/// Service for resolving dependencies.
		/// </summary>
		private IResolver resolverService { get; }

		public DefaultGameObjectFactory(IResolver resolver)
		{
			if (resolver == null)
				throw new ArgumentNullException(nameof(resolver), $"Provided {nameof(IResolver)} service provided is null.");

			resolverService = resolver;
		}

		/// <summary>
		/// Creates an empty <see cref="GameObject"/>.
		/// </summary>
		/// <returns>A non-null empty <see cref="GameObject"/>.</returns>
		public GameObject Create()
		{
			//Default GameObjects don't require dependencies
			return new GameObject();
		}

		/// <summary>
		/// Creates an instance of the prefab <see cref="GameObject"/>.
		/// </summary>
		/// <param name="prefab">Prefab to create an instance of.</param>
		/// <returns>A non-null instance of the provided <see cref="GameObject"/> <paramref name="prefab"/>.</returns>
		public GameObject Create(GameObject prefab)
		{
			//Create the GameObject and inject dependencies
			return InjectDependencies(GameObject.Instantiate(prefab));
		}

		private GameObject InjectDependencies(GameObject obj)
		{
			//Now inject dependencies into its components
			InjecteeLocator<MonoBehaviour> injecteeLocator = new InjecteeLocator<MonoBehaviour>(obj);

			foreach (MonoBehaviour mb in injecteeLocator)
			{
				Injector injecter = new Injector(obj, resolverService);

				injecter.Inject();
			}

			return obj;
		}

		/// <summary>
		/// Creates an instance of the prefab <see cref="GameObject"/> with the provided position and rotation.
		/// </summary>
		/// <param name="prefab">Prefab to create an instance of.</param>
		/// <returns>A non-null instance of the provided <see cref="GameObject"/> <paramref name="prefab"/>.</returns>
		public GameObject Create(GameObject prefab, Vector3 position, Quaternion rotation)
		{
			return InjectDependencies(GameObject.Instantiate(prefab, position, rotation) as GameObject);
		}
	}
}<commit_msg>Fix Fault with GameObject injection<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace SceneJect.Common
{
	public class DefaultGameObjectFactory : IGameObjectFactory
	{
		/// <summary>
		/// Service for resolving dependencies.
		/// </summary>
		private IResolver resolverService { get; }

		public DefaultGameObjectFactory(IResolver resolver)
		{
			if (resolver == null)
				throw new ArgumentNullException(nameof(resolver), $"Provided {nameof(IResolver)} service provided is null.");

			resolverService = resolver;
		}

		/// <summary>
		/// Creates an empty <see cref="GameObject"/>.
		/// </summary>
		/// <returns>A non-null empty <see cref="GameObject"/>.</returns>
		public GameObject Create()
		{
			//Default GameObjects don't require dependencies
			return new GameObject();
		}

		/// <summary>
		/// Creates an instance of the prefab <see cref="GameObject"/>.
		/// </summary>
		/// <param name="prefab">Prefab to create an instance of.</param>
		/// <returns>A non-null instance of the provided <see cref="GameObject"/> <paramref name="prefab"/>.</returns>
		public GameObject Create(GameObject prefab)
		{
			//Create the GameObject and inject dependencies
			return InjectDependencies(GameObject.Instantiate(prefab));
		}

		private GameObject InjectDependencies(GameObject obj)
		{
			//Now inject dependencies into its components
			InjecteeLocator<MonoBehaviour> injecteeLocator = new InjecteeLocator<MonoBehaviour>(obj);

			foreach (MonoBehaviour mb in injecteeLocator)
			{
				Injector injecter = new Injector(mb, resolverService);

				injecter.Inject();
			}

			return obj;
		}

		/// <summary>
		/// Creates an instance of the prefab <see cref="GameObject"/> with the provided position and rotation.
		/// </summary>
		/// <param name="prefab">Prefab to create an instance of.</param>
		/// <returns>A non-null instance of the provided <see cref="GameObject"/> <paramref name="prefab"/>.</returns>
		public GameObject Create(GameObject prefab, Vector3 position, Quaternion rotation)
		{
			return InjectDependencies(GameObject.Instantiate(prefab, position, rotation) as GameObject);
		}
	}
}
{'fraction_non_alphanumeric': 0.12434285714285714, 'fraction_numerical': 0.00045714285714285713, 'mean_word_length': 3.9113355780022445, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2366425', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1251, 'n_words': 362}