Exemplo n.º 1
0
        public static IArrangeDependencies Config <TInterface, TImplementation>(Action <IArrangeBuilder <ContainerBuilder> > config = null)
            where TInterface : class
            where TImplementation : class, TInterface
        {
            var arrangeBuilder = new ArrangeBuilder();

            config?.Invoke(arrangeBuilder);

            arrangeBuilder.UseImplementation <TInterface, TImplementation>();

            var containerBuilder = arrangeBuilder.Build();

            containerBuilder.Register((context) =>
            {
                var constructors = typeof(TImplementation).GetConstructors();
                var parameters   = constructors.SelectMany(x => x.GetParameters()).Where(x => x.ParameterType.IsInterface).Distinct();
                var args         = new List <object>();

                foreach (var parameter in parameters)
                {
                    args.Add(context.ResolveOptional(parameter.ParameterType) ?? MockHelper.CreateMock(parameter.ParameterType));
                }

                return(Activator.CreateInstance(typeof(TImplementation), args.ToArray()) as TImplementation);
            }).As <TInterface>().IfNotRegistered(typeof(TInterface));

            var container = containerBuilder.Build();

            return(new ArrangeDependencies(container));
        }
Exemplo n.º 2
0
        public static IArrangeDependencies Config(Action <IArrangeBuilder <ContainerBuilder> > config = null)
        {
            var arrangeBuilder = new ArrangeBuilder();

            config?.Invoke(arrangeBuilder);

            var containerBuilder = arrangeBuilder.Build();
            var container        = containerBuilder.Build();

            return(new ArrangeDependencies(container));
        }