Inheritance: IFabricContext
Ejemplo n.º 1
0
        /// <summary>
        /// Builds a dependency.
        /// </summary>
        /// <param name="typeToBuild">
        /// Specifies the type to be build.
        /// </param>
        /// <param name="container">
        /// Specifies the automocking container.
        /// </param>
        /// <returns>
        /// The created instance.
        /// </returns>
        public object Build(Type typeToBuild, IContainer container)
        {
            Guard.AgainstArgumentNull(typeToBuild, "typeToBuild");
            Guard.AgainstArgumentNull(container, "container");

            var buildContext = new FabricContext(typeToBuild, _mockingEngine, container, this);

            var responsibleBuilder = _builders.FirstOrDefault(x => x.KnowsHowToBuild(buildContext.TypeToBuild));

            if (responsibleBuilder == null)
            {
                throw new InvalidOperationException(
                          string.Format("Unable to build ctor dependency of type {0}." + Environment.NewLine +
                                        "Make sure to use only interfaces or abstract base classes in the constructor!", typeToBuild.FullName));
            }

            var stub = responsibleBuilder.BuildFrom(buildContext);

            Guard.AgainstArgumentNull(stub, "stub");

            _configurationRules.Each(x => x.Configure(stub, buildContext));

            return(stub);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds a dependency.
        /// </summary>
        /// <param name="typeToBuild">
        /// Specifies the type to be build.
        /// </param>
        /// <param name="container">
        /// Specifies the automocking container.
        /// </param>
        /// <returns>
        /// The created instance.
        /// </returns>
        public object Build(Type typeToBuild, IContainer container)
        {
            Guard.AgainstArgumentNull(typeToBuild, "typeToBuild");
            Guard.AgainstArgumentNull(container, "container");

            var buildContext = new FabricContext(typeToBuild, _mockingEngine, container, this);

            var responsibleBuilder = _builders.FirstOrDefault(x => x.KnowsHowToBuild(buildContext.TypeToBuild));

            if (responsibleBuilder == null)
            {
                throw new InvalidOperationException(
                    string.Format("Unable to build ctor dependency of type {0}." + Environment.NewLine +
                                 "Make sure to use only interfaces or abstract base classes in the constructor!", typeToBuild.FullName));
            }

            var stub = responsibleBuilder.BuildFrom(buildContext);

            Guard.AgainstArgumentNull(stub, "stub");

            _configurationRules.Each(x => x.Configure(stub, buildContext));

            return stub;
        }