ipjohnson / Grace

Grace is a feature rich dependency injection container library
MIT License
337 stars 33 forks source link

Properties not expected in a fluent API #88

Closed crystalbyte closed 7 years ago

crystalbyte commented 7 years ago

I was just wondering as to why a property was chosen for setting the Lifestyle instead of a method. To me it was very unintuitive, since it breaks the usual fluent API sequence.

ipjohnson commented 7 years ago

hi @crystalbyte, the reason for choosing a property for Lifestyle is that it forces the developer to chose a lifestyle or else it won't compile.

// compiles
registrationBlock.Export<SomeExport>().As<ISomeInterface>().Lifestyle();

// doesn't compile
registrationBlock.Export<SomeExport>().As<ISomeInterface>().Lifestyle;

"To me it was very unintuitive, since it breaks the usual fluent API sequence."

I'm not sure I follow this statement. The lifestyles return values, can continue the fluent sequence as seen below.

registrationBlock.Export<MultipleService1>().As<IMultipleService>()
          .Lifestyle.Singleton().When.ClassHas(typeof(ClassDataAttribute)).ImportProperty(m => m.Count);
crystalbyte commented 7 years ago

Hi, I am sorry for I have expressed myself poorly. The sequence is not actually broken, it is merely deviating from the regular pattern used in most of the other methods. It seems a little unclean to me.

I was expecting something more like registrationBlock.Export<SomeExport>().As<ISomeInterface>().AsSingleton() or registrationBlock.Export<SomeExport>().As<ISomeInterface>().WithLifestyle(new CustomLifestyle())

I hope this clarifies things.

ipjohnson commented 7 years ago

@crystalbyte it actually used to be that way but I found the interface was just becoming to large and it was hard to find things. It was really just a means of organizing lifestyles and conditions (with the intention that more will be added over time).

I think it's a personal preference, what seems intuitive to one person seems obtuse to another.

crystalbyte commented 7 years ago

Thanks for the clarification. On this topic we seem to have different tastes, but then I do not mind pineapple on my pizza, so perhaps it's just me :P

ipjohnson commented 7 years ago

Since it's me that's breaking from the norm it's probably my tastes that are a bit odd. That said I think we can both agree pineapple does work well on pizza.