Questioning one of the arguments for dependency injection frameworks: Why is creating an object graph hard?

Dependency injection frameworks like Google Guice give the following motivation for their usage (source):

To construct an object, you first build its dependencies. But to build each dependency, you need its dependencies, and so on. So when you build an object, you really need to build an object graph.

Building object graphs by hand is labour intensive (…) and makes testing difficult.

But I don’t buy this argument: Even without a dependency injection framework, I can write classes which are both easy to instantiate and convenient to test. E.g. the example from the Guice motivation page could be rewritten in the following way:

class BillingService {     private final CreditCardProcessor processor;     private final TransactionLog transactionLog;      // constructor for tests, taking all collaborators as parameters     BillingService(CreditCardProcessor processor, TransactionLog transactionLog)     {         this.processor = processor;         this.transactionLog = transactionLog;     }      // constructor for production, calling the (productive) constructors of the collaborators     public BillingService()     {         this(new PaypalCreditCardProcessor(), new DatabaseTransactionLog());     }      public Receipt chargeOrder(PizzaOrder order, CreditCard creditCard)     {         ...     } } 

So there may be other arguments for dependency injection frameworks (which are out of scope for this question!), but easy creation of testable object graphs is not one of them, is it?

datatable convertion error No overload for method ‘ToString’ takes 1 arguments

I have a code to convert data table column to string which generates following error

string fromDate = datatable.Rows[0]["FromDateAndTime"].ToString("yyyy-MM-dd HH:mm:ss.000"); 

error : No overload for method ‘ToString’ takes 1 arguments

just want to get the output as ‘2018-11-19 06:00:00.000’ and assign it to fromDate variable

Can a symbolic link provide default arguments?

I’m playing around with the SoX, an audio conversion program. After installation I notice that it creates a symbolic link /usr/bin/play -> sox. I notice that I can play an audio file with play my_song.wav, but if I try sox my_song.wav I get an error about not having enough inputs specified.

I don’t understand this behavior because I didn’t think running a program through a symbolic link would be any different than running it through the target directly. What mechanism is allowing this difference in behavior?

Min function accepting varying number of arguments in C++17

Come across this problem once again in the book The Modern C++ Challenge (problem 18). Wonder how simple and elegant the implementation could be using C++17. Following is my solution. Ideas? ^_^

#include <algorithm>  template <typename Less, typename T, typename... Ts> constexpr const T& min(Less less, const T& a, const T& b, const Ts&... rems) {   if constexpr (sizeof...(rems)) {     return min(less, std::min(a, b, less), rems...);   }   else {     return std::min(a, b, less);   } } 

ManualRefresh of list view web part gives error: Accessing the ‘caller’ property of a function or arguments object is not allowed in strict mode

SP 2016 On Prem

I have a list view web part in my form. After adding a new item to the list via dialog box, I want to show the new item. (Without refreshing the entire page of course.)

The solution found here from bkwdesign works great in Chrome:

How to refresh a data view web part in place, without reloading the page?

$  ('#WebPartWPQ3').find('#ManualRefresh').click(); 

But when I try it in IE 11 I get the error:

Accessing the ‘caller’ property of a function or arguments object is not allowed in strict mode

I don’t have ‘use strict’ anywhere in my code so I don’t know what’s triggering this.

I found some posts that talked about changing this <meta http-equiv="X-UA-Compatible" content="IE=10"/> to reference IE 11. But I don’t have authority to change that and I don’t want to effect any other sites.

How can I get this to work on my individual site for IE 11? I’m open to using a different refresh method if that’s necessary.

Thank you

puppet code design: how to collect arguments into a string (avoiding possible duplicate declaration errros)

I’m having trouble with puppet (version 5.5) code design. I’ve written a component module to deal with ucarp. It make use of the module eyp-systemd to register an ucarp service within systemd. Now I would like to consume the ucarp module from two independant profile modules that manage different services (in my case actually haproxy and bind9). Essentially this looks like this:

class ucarp {   systemd::service { 'ucarp':     /* list of parameters */   } }  define ucarp::vip {   /* defines a virtual IP to be shared among several nodes */ }  /* ==================== */  class profile_haproxy {   include ::ucarp   ::ucarp::vip { 'haproxy': }   /* setup haproxy */ }  /* ===================== */  class profile_bind9 {   include ::ucarp   ::ucarp::vip { 'bind9': }   /* setup bind9 */ } 

This is straight forward and works well.

Now the actual issue: it is best practice to order the ucarp service after the services that are run over ucarp. This is possible using the after parameter:

class ucarp(   Array[String] $  after, ) {   systemd::service { 'ucarp':     after => $  after.join(' '),     /* list of other parameters */   } } 

This requires replacement of include ::ucarp by

class { ::ucarp:   after => ['haproxy'], } 


class { ::ucarp:   after => ['bind9'], } 

respectively. Of course this would immediately lead to a “duplicate declaration” error.

What I actually would like to have is a single instantiation of the class ucarp that collects all after parameters into one single string that can be passed to systemd::service. How would I do this?

Currently two possible solutions come to my mind:

  1. Fork eyp-systemd, remove the after parameter and replace it by a defined type, e.g. systemd::service::after. Internally the module then collects all instantes of systemd::service::after and all other information it needs into the resulting service declaration using richardc-datacat. This is something I really don’t want to do. Generally I shy away from modifying forge modules as I this forces me to maintain it on my own. In this case the introduction of datacat also seems like a major rewrite of the module.
  2. Introduce my own defined type in the ucarp module ucarp::order_after which does not do anyhing. The profile modules would define virtual instances of this type. The ucarp class could then use a puppetdb query to collect all instances of ucarp::order_after. The big drawback here is that I’m only dealing with virtual resources not with exported resources. So actually there is no need at all to involve puppetdb. So this would be an ugly work-around that forces me to always operate a puppetdb.

I hope there are other possibilities I can’t think of right now.

Discord seperate arguments to strings

I know, the question is not exactly the title, but I didn’t know how to phrase it in a short question. So: I also have a little command handler, and if the command would be ##test One Two Seven Three, there would be an array with the Items “One”, “Two”, “Seven” & “Three”. I also already know that I can join them, by using args.join(" "). But here’s the question now: If the command is ##test Example number one || And example two || And also a third one, I want to have an array called argStrings with the elements “Example number one”, “And example two” & “And also a third one”. So I want everything before/after/between “||” to be specific array items. I hope you can understand my question since my english is not the best :/ I am also still a coding newbie.

Resolving function calls as function arguments using a stack

After doing a bit of reading, I have a vague understanding of the use of a stack in calling functions when one function calls another, where the arguments are placed on the stack for the called function to retrieve them.

So, in the following example, calling the function add, would place the values 5 and 6 on the stack, then go to the start of the add function which would pop the values off the stack for each of its arguments.

function add(num1, num2) {     return num1 + num2; }  function doit() {     add(5, 6); } 

However, what happens when a function call takes place in the arguments, to another function, for example:

function subtract(num1, num2) {     return num1 - num2; }  function add(num1, num2) {     return num1 + num2; }  function doit() {     add(subtract(9, 7), 6); } 

In this example, the first operand is actually a function call (the call to subtract). So what is placed on the stack in this case in the call to add? How is the function call to subtract resolved before actually executing add?