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
6
votes
2 answers

What is the proper usage of HasColumnType and Database generated

I'm migrating a substantial EF model of ~80 entites from EF4 to EF6, and I'm also changing it from a Designer EDMX-generated database, to a Code First database. Right now I'm configuring the entity relationships using EF fluent-api, and I'm not…
kpk47
  • 88
  • 1
  • 1
  • 4
6
votes
2 answers

Fluent Interface and class complexity

Problem: Implementing fluent interface with many methods yields class complexity metric growing very fast. How to keep low complexity for class which implements fluent interface? Some information about specific class: Class already has 25 methods…
Im0rtality
  • 3,463
  • 3
  • 31
  • 41
6
votes
2 answers

How to create a Fluent Interface with Generics

I wanted to create a fluent interface that can be used like so: void Main() { ModelStateMappings.MapDomainModel().MapViewModel() .Properties(book => book.Author, vm => vm.AuthorsName) .Properties(book =>…
Evan Larsen
  • 9,935
  • 4
  • 46
  • 60
6
votes
2 answers

EF Code First: Multiplicity constraint violation

HELP! - I am receiving the following error on my navigational model ArticleType: A relationship multiplicity constraint violation occurred Here is the existing database schema: Here is my code: public class Article { public int ID { get; set;…
Yorro
  • 11,445
  • 4
  • 37
  • 47
6
votes
2 answers

How to implement fluent api in ASP.NET MVC?

I want to implement fluent api to my mvc sites. I got the basics. So implement object library such as: public class UIElement{/*...*/} public class ButtonBase : UIElement{/*...*/} public class LinkButton : ButtonBase {/*...*/} public static class…
Péter
  • 2,161
  • 3
  • 21
  • 30
5
votes
1 answer

Why must we assign a clone to a new variable?

I am currently learning to use the Propel ORM, and I want to reuse a critera for two slightly different queries: $criteria = ArticleQuery::create() ->filterByIsPublished(true) ->orderByPublishFrom(Criteria::DESC) …
CheeseSucker
  • 1,270
  • 1
  • 9
  • 13
5
votes
3 answers

Is it possible to set a breakpoint in a method chain in VS, and if so how?

Given the code [Test] public void Test1() { var a = new A(); a .Method1() .Method2(); } is it possible to set a breakpoint so that execution pauses after Method1() has executed, but before…
5
votes
2 answers

EF 4.1 RC Code First - Mapping to existing database & specifying foreign key name

I have two classes. A Company has a County set against it: public class Company { public int Id { get; set; } public string CompanyName { get; set; } public Country HomeCountry { get; set; } } public class Country { public int Id {…
P2l
  • 915
  • 2
  • 11
  • 25
5
votes
2 answers

EF 4.1 RC Many to many relationship in EF CF

I have two entities with many to many relationship like this: class author { public int AuthorID{get;set;} public string Name{get;set;} public virtual ICollection books{get;set;} } class book { public int BookID{get;set;} public…
5
votes
1 answer

Fluent Interface (Java) for object with getters and setters

I read and enjoyed the article http://blog.jooq.org/2012/01/05/the-java-fluent-api-designer-crash-course/ from Lukas Eder and I would like to create a Fluent Interface for a class. The class has four functions ("words" fill1 to fill4) that allow to…
Make42
  • 12,236
  • 24
  • 79
  • 155
5
votes
1 answer

entity framework code first attributes in combination with fluent api configurations

Can I use code first attributes in combination with fluent-API configurations for my entities in Entity Framework? Thank you.
Zole
  • 69
  • 5
5
votes
1 answer

how do closures help in creating a DSL/fluent interface: PHP examples?

Can you give me an example, in PHP, that shows how closures are helpful in creating a DSL (fluent interface)? edit: The accepted answer in the following question tells about nested closures. If someone could translate that example to PHP that would…
koen
  • 13,349
  • 10
  • 46
  • 51
5
votes
1 answer

Fluent interface design and code smell

public class StepClause { public NamedStepClause Action1() {} public NamedStepClause Action2() {} } public class NamedStepClause : StepClause { public StepClause Step(string name) {} } Basically, I want to be able to do something like…
Jiho Han
  • 1,610
  • 1
  • 19
  • 41
5
votes
1 answer

BaseFoo cannot be inherited with different arguments: > and >

This is a simplified version of Java inherited Fluent method return type in multiple level hierarchies. Given the following code: public enum X { ; static interface BaseFoo> { S foo(); } static…
Gelin Luo
  • 14,035
  • 27
  • 86
  • 139
5
votes
3 answers

Combine Fluent and XML mapping for NHibnernate

I just fell in love with NHibernate and the fluent interface. The latter enables very nice mappings with refactoring support (no more need for xml files). But nobody is perfect, so I am missing the many-to-any mapping in fluent. Does anybody know if…
Christian
  • 123
  • 1
  • 6