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

Castle Windsor: Auto-register types from one assembly that implement interfaces from another

I use Castle Windsor as my IoC container. I have an application that has a structure similar to the following: MyApp.Services.dll IEmployeeService IContractHoursService ... MyApp.ServicesImpl.dll EmployeeService :…
Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220
10
votes
2 answers

Understanding of How to Create a Fluent Interface

Hi i'm trying to understand how i could build a readable and also error preventing Fluent-API without to much restriction for the User to hold it simple let's say we want to change the following class to be fluent public class Car { public int…
WiiMaxx
  • 5,322
  • 8
  • 51
  • 89
9
votes
1 answer

Inheritance EF Code-First

I have a base object that I dont want to be mapped in DB as an entity, I only want the properties to be added to the object that is mapped in the DB : Not mapped object (dont know if it matters but baseobject is in another assembly): public class…
Pierluc SS
  • 3,138
  • 7
  • 31
  • 44
9
votes
1 answer

Self bound generic type with fluent interface and inheritance

I am using a fluent interface with inheritance. I declared the base class Constructor protected so you cant create a Foo which would result in a ClassCastException on calling add(). But i am having trouble with the static method that returns a…
Stefan
  • 838
  • 3
  • 13
  • 28
9
votes
2 answers

Entity Framework Code First Case Sensitivity on string PK/FK Relationships

I have a fairly simple composite one to many relationship defined using POCO/Fluent API, one column of which is a string. I've discovered that the data in this column in our database is inconsistent in terms of case ie 'abb', 'ABB' - this is our…
9
votes
1 answer

Unable to send embedded image in email using FluentEmail

I'm using FluentEmail in ASP.NET core 2.0 class library which will be sending the Email notification. Below is the sample code I have tried till now: using FluentEmail.Core; using FluentEmail.Razor; using FluentEmail.Smtp; using System; using…
I Love Stackoverflow
  • 6,738
  • 20
  • 97
  • 216
9
votes
4 answers

Is there a fluent email library for c#?

I've been writing a bunch of email code lately and it occurred to me that it'd be pretty cool if there was a library that allowed you to fluently create an email in c#. I had a quick look around but couldn't find anything so was wondering if anyone…
lomaxx
  • 113,627
  • 57
  • 144
  • 179
9
votes
7 answers

Recursive Generic and Fluent Interface

tl;dr Trying to implement a hierarchal fluent interface such that I can combine nodes child classes while also the class standalone, but getting type parameter is not within its bound errors. Details I'm trying to achieve a solution so that I can…
SS44
  • 837
  • 2
  • 10
  • 26
9
votes
2 answers

Do fluent interfaces significantly impact runtime performance of a .NET application?

I'm currently occupying myself with implementing a fluent interface for an existing technology, which would allow code similar to the following snippet: using (var directory = Open.Directory(@"path\to\some\directory")) { using (var file =…
9
votes
1 answer

Entity Framework and generics

I have a couple independent objects, each of which has a list of a common object. For instance, public class Project { public IEnumerable> Comments{get;set;} } public class Sample { public…
KillerCoder
  • 93
  • 1
  • 3
9
votes
3 answers

How do I unit test code that uses a Fluent interface?

I've created a few small fluent interfaces through method chaining. They typically call a number of Repositories that fetch data from webservices / databases. How should I go about unit testing methods that use the fluent interface? Public…
Andronicus
  • 1,799
  • 1
  • 14
  • 28
9
votes
5 answers

Fluent interfaces and inheritance in C++

I'd like to build a base (abstract) class (let's call it type::base) with some common funcionality and a fluent interface, the problem I'm facing is the return type of all those methods class base { public: base(); virtual…
blaxter
  • 335
  • 3
  • 10
8
votes
1 answer

EF Code First - Fluent API (WithRequiredDependent and WithRequiredPrincipal)

I have the following class: public class User { public Guid Id { get; set; } public string Name { get; set; } public Couple Couple { get; set; } } public class Couple { public Guid Id { get; set; } public User Groom { get; set;…
ridermansb
  • 10,779
  • 24
  • 115
  • 226
8
votes
2 answers

How do you use Castle Windsor - Fluent Interface to register a generic interfaces?

Castle Windsor just came out with a Fluent interface for registering components as an alternative to using XML in a config file. How do I use this Fluent interface to register a Generic interface? To illustrate, I have: public interface IFoo { …
Phil
  • 2,143
  • 19
  • 44
8
votes
4 answers

Entity Framework Code First Mapping Foreign Key Using Fluent API

I have the situation where a User can have several addresses. Accordingly, I have an ICollection on my user class. But I also want the user to be able to choose a default address. So I've done the following: public class User { public int Id {…