fluent-interface

Windsor Fluent Interface Lifestyle

Are these equivalent syntaxes for setting component lifestyle? Component.For<IFoo>() .ImplementedBy<Foo>() .LifeStyle.Is(LifestyleType.Transient) Component.For<IBar>() .ImplementedBy<Bar>() .LifeStyle.Transient ...

F#: Best way to de-fluent an API?

I'm extending Fluent NHibernate for better use with F# (namely, quotation support), and want some feedback on de-fluenting the API. F# requires that return values be used, unless they are type unit. So this ends up terminating every line with "|> ignore": type ProductMap() as m = inherit QClassMap<Product>() do let x = Unchecked.def...

How do I refactor chained methods?

Starting with this code: new Person("ET").WithAge(88) How can it be refactored to: new Person("ET", 88) What sequence of refactorings needs to be performed to complete the transformation? Why? Because there could be hundreds of these, and I wouldn't want to introduce errors by doing it manually. Would you say a drawback with f...

C#: Returning 'this' for method nesting?

I have a class that I have to call one or two methods a lot of times after each other. The methods currently return void. I was thinking, would it be better to have it return this, so that the methods could be nested? or is that considerd very very very bad? or if bad, would it be better if it returned a new object of the same type? Or w...

Getting a parameterless method to act like a Func<ReturnT>

I'm trying to make a part of my code more fluent. I have a string extension that makes an HTTP request out of the string and returns the response as a string. So I can do something like... string _html = "http://www.stackoverflow.com".Request(); I'm trying to write an extension that will keep trying the request until it succeeds. My ...

Fluent interfaces / extension methods - Turning a flat list into a navigation tree

I currently have an extension Method which converts an IEnumerable of type Tab into a hierarchical collection of TabNodes. // If Tab has no parent its ParentId is -1 public class Tab { public int TabId { get; set; } public string TabName { get; set; } public int Level { get; set; } public int ParentId { get; set; } } publ...

Does "Select New" in linq trigger an evaluation / load?

I'm currently trying to create a class which implements IEnumerable<T> in order to construct a Hierarchy from a flat list of objects which have references to each other through a ParentId property. I'd like to write a fluent interface for this so I can do something like this IEnumerable<Tab> tabs = GetTabs(); IEnumerable<TabNode> tabNo...

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 Pick() method does nor can I find any documentation. Can anyone explain it to me? ...

Castle Windsor Fluent API: How to set a component parameter value to a configured property

Hi, I am just getting started with the Fluent registration for Castle Windsor and cant figure out how I can reference properties I have defined in the properties section of my XML configuration file when registering. So I have this code to register a component. RegisterComponent(componentId, Component.For<ConnectionConfig>() ...

Dealing with asynchronous control structures (Fluent Interface?)

The initialization code of our Flex application is doing a series of asynchronous calls to check user credentials, load external data, connecting to a JMS topic, etc. Depending on the context the application runs in, some of these calls are not executed or executed with different parameters. Since all of these calls happen asynchronousl...

Finding the right pattern for loading objects with different graphs

I'm trying to figure out the best way to handle loading objects with different graphs (related entities) depending on the context their being used. For example Here's a sample of my domain objects: public class Puzzle { public Id{ get; private set; } public string TopicUrl { get; set; } public string EndTopic { get; set; } ...

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 ~base(); base& with_foo(); base& with_bar(); protected: // whatever.....

Mixing fluent and non-fluent interface in one class

I consider fluent interfaces very convenient for many tasks. But I feel uneasy when I end up mixing fluent methods and modifying methods in one class. Just an example (it's a little contrived, please bear with me): Assuming a string utility class, trimming seems good for chaining: Str & Str::Trim() { return TrimLeft().TrimRight(); }...

Method chaining - why is it a good practice, or not?

Method chaining is the practice of object methods returning the object itself in order for the result to be called for another method. Like this: participant.addSchedule(events[1]).addSchedule(events[2]).setStatus('attending').save() This seems to be considered a good practice, since it produces readable code, or a "fluent interface"....

Fluent Interfaces - the number of objects being created

Hi guys I am in the process of creating some fluent interfaces for some simple validation stuff that I am playing around with. One thing that I have noticed is that I have a lot of different objects being created. For instance given the below statements: Check.Assertion.ForValue.That(value, "value").IsNotNull() : void Check.Assertio...

Which is more fluent - longer or shorter syntax?

Hi guys I am trying to create my first fluent interface and I was just wondering what other poeple thought was more fluent and which one they would prefer to use? Check.Field().Named("est").WithValueOf("sdsd").IsNotNull() Check.Field("est").WithValueOf("sdsd").IsNotNull() Check.Field("est").WithValue("sdsd").IsNotNull() Cheers Anth...

Castle Interceptors With Fluent Interface

I'm trying to get an interceptor I've written to work, but for some reason it doesn't seem to be instantiating the interceptor when I request my components. I'm doing something like this (forgive me if this doesn't quite compile, but you should get the idea): container.Register( Component.For<MyInterceptor>().LifeStyle.Transient, ...

Implementing conditional in a fluent interface

I've been trying to implement a fluent interface for a set of rules in my system. What I am trying to accomplish is this TicketRules .RequireValidation() .When(quartType => quartType == QuartType.Before).TotalMilageIs(64) .When(quartType => quartType == QuartType.After).TotalMilageIs(128); However, I have trouble implementing the When...

How can I create a fluent interface for defining Dialog Boxes?

I am looking for examples and experience of using fluent interface to define simple Dialog Boxes (and other UI elements). (I may need to add support for custom Dialog Boxes to an in-house programming language and I think a fluent interface may be the best way of doing it) The UI system will be build on Winforms OR WPF if that effects ...

NHibernate: Deleting a collection and re-inserting

Hello, I have a User with related Permissions. Here is what I want: I create a User and add a permission to the User.Permissions collection. It gets saved and everything happens as expected. Then I edit the user and remove the permission. A new user object is then created and the permissions collection is empty. The identifier and...