Questions tagged [fluent-interface]

Refers to a practice of coding object-oriented APIs with the aim of improving readability of the interface, normally implemented using method chaining. The phrase was first coined by Eric Evans and Martin Fowler.

Martin Fowler's explanation on what he considers to be the proper way to design fluent interfaces can be found at http://www.martinfowler.com/bliki/FluentInterface.html.

Related concepts:

437 questions
7
votes
1 answer

How to debug fluent APIs?

Fluent APIs are awesome. They give concise and readable code. But it is a severe pain when something works as not expected. Are there any ways to see the intermediate results of the method calls chain in VS? May be some add-ins?
Pavel Voronin
  • 13,503
  • 7
  • 71
  • 137
7
votes
2 answers

Lambda Func<> and Fluent

There are lots of Fluent implementations out there now that work with Lambdas to do things that are quite neat. I'd like to wrap my brain around it so I can start creating some of these things, but I have yet to find an explanation that my brain…
ctorx
  • 6,841
  • 8
  • 39
  • 53
7
votes
2 answers

Fluent Interfaces - Ensuring a new instance

I have a class that exposes a fluent interface style that I also want to be thread safe. At the moment, calling chainable methods on an instance of the class sets up various collections with operations (Func's). When the result is requested the…
Jamie Dixon
  • 53,019
  • 19
  • 125
  • 162
6
votes
2 answers

Castle Windsor Fluent Registration - What does Pick() do?

When using auto-registration with castle windsor I see people doing things like _container.Register( AllTypes.Pick().FromAssembly(Assembly.GetExecutingAssembly()) .WithService.FirstInterface()); For the life of me I can't figure out what the…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
6
votes
1 answer

Entity Framework - Code First Fluent API: ErrorMessage?

I'd like to use localised validations with the Fluent API like this in Data Annotations: [Required(ErrorMessageResourceName = "Domain_Address_AddressTypeRequired", ErrorMessageResourceType = typeof(Resources))] public virtual AddressType …
Oszkar
  • 1,603
  • 3
  • 15
  • 17
6
votes
1 answer

Using generic constraints with value types

I am experimenting with fluent extension methods. I have the following simple extension method to perform a safe cast. public static T As(this Object source) where T : class { return source as T; } This worked…
David Culp
  • 5,354
  • 3
  • 24
  • 32
6
votes
2 answers

EF Code First: Many-to-many and one-to-many

This is probably just because my knowledge with the EF Code First fluent API is lacking, but I'm stumped. I want to model the following: A Groups collection with Id and Name A Users collection with Id and Name Each user is assigned to exactly one…
6
votes
1 answer

EF Code First 4.1 - How to configure one to many relationship with default

I have a Customer entity which references a collection of Addresses. The complication here is that I want to be able to identify a particular address as the default address. If possible I would like to hold the FK of the default address in the…
P2l
  • 915
  • 2
  • 11
  • 25
6
votes
2 answers

Code-First Reference one-to-many

I have the following two tables: LOCALIZATION Id int Text string DINER Id int Name string Description string Name_LocalizationID int Description_LocationID…
sadhat75
  • 191
  • 4
  • 9
6
votes
4 answers

What conventions/idioms/patterns are you using configuring IOC Containers using the new Fluent Interfaces

I am in the middle of moving over a large body of code to Castle Trunk which includes the new fluent interface for configuring the container. Since the project has a huge windsorConfig xml file that is beyond maintainable, I thought I would start to…
Nic Strong
  • 6,532
  • 4
  • 35
  • 50
6
votes
0 answers

Fluent setters on child and parent Classes in PHP

I am having some issues with the concept of fluent setters. I created 2 classes that extends from the same parent. And I put the common attributes between them in the parent class and I want to put the setters there , to avoid repeating the same…
JIFT
  • 81
  • 2
  • 6
6
votes
2 answers

Fluent interface with Python

I have a Python function "send_message" which takes three arguments: send_message("i like windmills", to="INBOX", from="OUTBOX") I am thinking about putting a fluent interface on top of it. Ideally I'd like to write any of the…
samba2
  • 468
  • 7
  • 15
6
votes
2 answers

Fluent Interface to Build a Directed Cyclic Graph?

I have created a set of classes to represent a directed cyclic graph for representing BPM processes, based on JUNG's DirectedSparseGraph class, which provides only basic graph manipulation methods to add and find vertices and edges. The challenge I…
izilotti
  • 4,757
  • 1
  • 48
  • 55
6
votes
2 answers

How to use "JSR-353: Java API for JSON Processing," without Method Chaining

I wanted to share my question/answer with using the new JSR-353 which is the Java API for JSON Processing. Specifically you can manipulate JSON data in 2 different "API" the Streaming and the Object API. If you type in "jsr-353 tutorial" into…
XaolingBao
  • 1,034
  • 1
  • 18
  • 34
6
votes
1 answer

Detecting end of method chain in PHP?

I cannot find a simple example about my question above: how can i detect the end of a method chain? I'm just looked Zend_Db_Select for example but this one is too complex for this simple question i think. Is it possible to catch the 'end' of a…
fabrik
  • 14,094
  • 8
  • 55
  • 71