Open sshushliapin opened 8 years ago
:+1:
I very much like the idea!
I was thinking about the semantic though and I'm not sure I like bolting on extension methods to the Db
object. It looks a little bit out of place. I was searching for an example and fluent assertions come to mind with their Should()
.
What if if we did something like Db.Api.Create()
or even Db.Api().Create()
anticipating future overloads?
Just thinking out loud. Again, fully support the idea of having a shortcut API for add-and-get. But if it's a beginning of a fluent API of sort then maybe Db
itself is not a good home for new extension methods?
Thought? Am I overthinking?
Sent from my iPhone
On Oct 27, 2015, at 2:56 PM, Kam Figy notifications@github.com wrote:
— Reply to this email directly or view it on GitHub.
So, technically it is possible to return an Item
from the existing db.Add()
methods. It'll not be a breaking change and there are no new methods needed in this case.
I just have a feeling that the Add() method should always be void and Create() should return some result. Tried to find examples in .NET and Sitecore API but realized that it's not so obvious. There are numerous variants available...
I don't think there is a place for the fluent API. There are two user scenarios:
Item
instances right here in the test, I might get them in my SUT later if necessary. Db.Add() or collection initializers are used.Item item = db.Create("home")
.But.. looking on the second scenario, I also have a feeling that smth is wrong here...
//cc: @kamsar
The alternative might be to introduce builders. For instance:
var item1 = db.Build<Item>().FromDbItem(new DbItem("root"));
var item2 = db.Build<Item>().WithName("home");
@pveller Yep, that is the fluent API :-D
Totally! :) I knew something was wrong with the db.Create()
and I also remember mentioning the fluent API back when @kamsar asked for the simple add-and-get.
I like it a lot. Builders it is!
Asked by @kamsar in Twitter. The problem is that in order to get an
Item
instance, one have to write three lines of code:There is a suggestion to introduce new
db.Create()
extension method which would combine theAdd()
andGetItem()
functionality: