question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StaticCommand - dependency injection

See original GitHub issue

Since the static command uses static methods, we cannot do dependency injection easily. We should allow to call also instance methods from the staticCommand binding. The class which contains the method would be instantiated for every command and this could be extended by IoC/DI.

Also, we should introduce the StaticCommandHandlerBase class and the IStaticCommandHandler interface which will have the Context property to allow to interact with the HTTP request. This property would by injected by the framework automatically.

It will be optional to implement this interface, I think we can allow static command targets in any class.

However, to keep things secure, any method called from the binding will have to be marked with the AllowStaticCommand attribute.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
exyicommented, Dec 11, 2016

Static commands of course works with static commands, they are just not resolved from scope parameter by the resolver - so you have to type ViewModel.SomeCommand(). Instance static commands work exactly the same way as static static commands, the this parameter is just passed as any other parameter, it has no special meaning, technically it work exactly the same like static methods. It does not send the entire view model to the server, it only sends the parameters, including the possible this parameter. So it send the entire viewModel iff you call it on root viewModel, it may be completely reasonable in some situations IMO, but it is your choice. It is also reasonable to use it on parts of the viewmodel, something like GetEntireText() on ArticleInfo.

Just a note, the tests will not help at all, we are not talking now about bugs but about flaws in the design. We’d write the tests to match these flaws so they will be completely useless, we would just have to rewrite them with fixing these flaws, so it will be two times more expansive. The discussion can help, hopefully 😃.

0reactions
exyicommented, Sep 7, 2017

resolved in #416

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dependency Injection vs. Static Access - Programming
Dependency Injection is a practice of passing your dependencies into the methods (or classes) that use them. This is the what the original...
Read more >
Dependency injection and static methods - java
I was wondering how I can make a static method work with dependency injection. ... This is kinda what I want to do,...
Read more >
Static Command Binding | DotVVM Documentation
A static command allows to call a method on the server and use its result to update a particular property of the viewmodel....
Read more >
Usage of objects as services in static functions
Dependency injection. Most developers experience this kind of pattern: You want to parse some XML; You don't want to use the bulky and...
Read more >
Laravel: When to Use Dependency Injection, Services and ...
But there are a few ways to use them – as static “helpers”, as objects, or with Dependency Injection. Let's see when each...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found