Name of this idiom? myFont.setWidth(20).setStyle(Style.BOLD).setX().setY().setZ() (...) - idioms

Is there a standard way to refer to this idiom of "telescopic" method call chaining?
myFont.setWidth(20).setStyle(Style.BOLD).setX().setY().setZ() (...)

A library that uses this style is said to have Fluent API or Fluent interface. An example of this is a Fluent Validation library.

It is simple called "Method chaining" according to wikipedia
http://en.wikipedia.org/wiki/Method_chaining

Related

What do you call the method DI uses to populate a model?

Implementations of IHost like the generic host do dependency injection. You populate a services collection with helper methods like this
IConfigurationSection section;
section = config.GetSection("SectionName");
services.Configure<SectionModel>(section);
Inside the Configure helper method some magic creates an instance of SectionModel and populates it from the IConfigurationSection object.
What is that called? I need to do it in the absence of the DI and while I'm sure rummaging through Microsoft source code would probably yield answers I could rummage a lot faster armed with the name of the method that does it.
More than likely they just use reflection, but I'd prefer not to implement this myself and have potentially divergent behaviour.
According to documentation this is called Bind and is surfaced on IConfigurationSection.
First you create the config section and model objects, then you call Bind like so
var sectionModel = new SectionModel();
config.GetSection("SectionName").Bind(sectionModel);
#Nkosi comments
The same can be done using
var sectionModel = config.GetSection("SectionName").Get<SectionModel>();
This is a more elegant expression of the same solution using generics.

Symfony Dependency injection serivces.yaml configurtion by interface

I'm looking for solution of my problem.
I wonder if i can do something like this:
App\Product\Domain\ProductSaver: '#App\Product\Infrastructure\Saver\ProductJsonSaver'
But i want to use it too:
App\Product\Domain\ProductSaver: '#App\Product\Infrastructure\Saver\ProductORMSaver'
Depends of which User Interface call it.
For example if i call /product/save/database endpoint i want to use ProductORMSaver and if i call /product/save/file endpoint i want to use ProductJsonSaver. Is it possible? I found solution which rely on parameter name but i want to avoid it.

java : Is it possible to dynamically modify the code of a servlet's method (like doPost)

I'm trying to write a Framework like Spring MVC.
I'm looking for a way to modify the code of the doPost/doGet method of a servlet 3.0 deployed on tomcat using javassist or reflection or whatever so the doPost can call a service method dynamically defined .
doPost(...){
ServiceClassName.methodeName(); // dynamic line of code
}
Thanks
It is possible using javassist. Refer this to write your Transformer class.
Although I have never tried it before, have a look at http://www.bytebuddy.net for a bytecode creation/manipulation library.

is there a way to populate an existing object from json using json.net based upon an interface

Looking for a way to do something like the following:
NewtonSoft.Json.JsonConvert.Populate<IMyContract>(jsonStr, currentObj);
where the json.net engine would only attempt to populate the properties that are identified in the IMyContract.
Any suggestions?
Maybe u can use
PopulateObject(String, Object, JsonSerializerSettings)
And use your own JsonSerializerSettings. See: http://james.newtonking.com/projects/json/help/html/T_Newtonsoft_Json_JsonSerializerSettings.htm
Try to use one of the delegates to restrict the properties that are set yourself. That can be based on an Interface, using reflection.
I don't know any other way. If you don't get it with the JsonSerializerSettings you can always write your own PopulateObject method using the Json framework.

Which Scala features are internally implemented using reflection?

It is a well known fact that structural types are implemented through reflection. Are there maybe any other language constructs which use reflection?
This is closely related to structural types, but any anonymous object instance, ie
new { def print = ("hello world") }.print
will use reflection.
http://scala-programming-language.1934581.n4.nabble.com/Structural-types-reflection-td3071599.html
Enumerations use reflection to find out about all of the possible values for the enumeration for the nameOf function. (See the populateNameMap method in Enumeration.scala). This is done once, the first time you call nameOf for a particular Enumeration type.
If you consider isInstanceOf/asInstanceOf as reflection, then pattern matching relies on them
Method invocation in structural types depends on reflection:
type T = { def startsWith(x:String):Boolean }
def doSomethingWith(x:T) = x.startsWith("abc")
doSomethingWith("abcdef")
The Scala interpreter makes very heavy use of reflection.
It's not a language construct, but ScalaTest includes Suite.execute, which uses reflection to find and invoke test methods.
Does Scala's pattern matching use any reflection behind the scenes?

Resources