public void has_simple_argument() { var graph = ServiceGraph.For(x => x.AddTransient <IWidget, AWidget>()); var ctor = ConstructorInstance.For <WithSimples>().DetermineConstructor(graph, out var message); message.ShouldContain("* int number is a 'simple' type that cannot be auto-filled"); }
public void has_unknown_dependency() { var graph = ServiceGraph.For(x => x.AddTransient <IWidget, AWidget>()); var ctor = ConstructorInstance.For <WithHitsAndMisses>().DetermineConstructor(graph, out var message); message.ShouldContain("* int number is a 'simple' type that cannot be auto-filled"); message.ShouldContain( "* Rule is not registered within this container and cannot be auto discovered by any missing family policy"); }
public void do_not_pick_up_concrete_type_with_no_usable_ctor() { var graph = ServiceGraph.For(_ => { //_.AddTransient<IWidget, AWidget>(); //_.AddTransient<IClock, Clock>(); }); graph.TryToCreateMissingFamily(typeof(WidgetUser)) .Default.ShouldBeNull(); }
public void use_custom_policy() { var graph = ServiceGraph.For(_ => { _.Policies.OnMissingFamily <CustomMissingFamily>(); }); graph.TryToCreateMissingFamily(typeof(FakeThing)) .Default.ShouldBeOfType <ObjectInstance>() .Service.ShouldBeOfType <FakeThing>() .CreatedBy.ShouldBe("CustomMissingFamily"); }
public void can_pick_up_concrete_type_with_no_usable_ctor() { var graph = ServiceGraph.For(_ => { _.AddTransient <IWidget, AWidget>(); _.AddTransient <IClock, Clock>(); }); graph.TryToCreateMissingFamily(typeof(WidgetUser)) .Default.ShouldBeOfType <ConstructorInstance>() .ImplementationType.ShouldBe(typeof(WidgetUser)); }
public void register_an_instance_that_is_not_the_default() { var instance = ObjectInstance.For(new Clock()); var graph = ServiceGraph.For(_ => { _.Add(instance); _.AddSingleton(new Clock()); }); graph.FindInstance(instance.ServiceType, instance.Name) .ShouldBeSameAs(instance); }
public void custom_policies_take_precedence() { var graph = ServiceGraph.For(_ => { _.Policies.OnMissingFamily <CustomMissingFamily>(); }); graph.FamilyPolicies[0].ShouldBeOfType <CustomMissingFamily>(); graph.FamilyPolicies[1].ShouldBeOfType <EnumerablePolicy>(); graph.FamilyPolicies[2].ShouldBeOfType <FuncOrLazyPolicy>(); graph.FamilyPolicies[3].ShouldBeOfType <CloseGenericFamilyPolicy>(); graph.FamilyPolicies[4].ShouldBeOfType <ConcreteFamilyPolicy>(); graph.FamilyPolicies[5].ShouldBeOfType <EmptyFamilyPolicy>(); }
public void no_family_for_assembly_scanner_or_policy_or_connected_concretions() { var graph = ServiceGraph.For(_ => { _.Scan(x => { x.TheCallingAssembly(); x.ConnectImplementationsToTypesClosing(typeof(type_scanning.IGeneric <>)); }); _.Policies.OnMissingFamily <CustomMissingFamily>(); }); graph.HasFamily(typeof(ConnectedConcretions)).ShouldBeFalse(); graph.HasFamily(typeof(IFamilyPolicy)).ShouldBeFalse(); graph.HasFamily(typeof(AssemblyScanner)).ShouldBeFalse(); }