How to add the new Event Logger to a DNN Scheduler Class in DNN 9.10.2? - event-handling

How can I add a constructor with a reference to _eventLogger = DependencyProvider.GetRequiredService(); in a DNN Scheduler class?
The Dependency Provider can be inherited through the PortalModuleBase class, which I can do on my current Web Form module. The issue is that it is Protected and I can't inherit it again on the same View.ascx page in a Scheduler Class.

It is the same problem as in this post. Dependency injection in DNN is not (yet) available in Scheduler classes, only in webforms code-behind.

Related

Equivalent of #componentScan in dagger?

Sorry for this basic question I am asking but can someone tell me if dagger dependency injection can work just with #module, #provides #Inject etc. That is without using #component annotation?
In spring DI, we use #componentScan to let spring know where to find beans. What is the equivalent of this in dagger?
You always need #Component. This is the entry point for dependencies from "outside".
When I say "outside" I mean the case where after the dependency graph inside the Component is created and now it is a time for some Activity to be Injected for example. So the component exposed dependencies for the "outside".
At the same time, a component can share its dependencies with other Subcomponents for example.
The Components depend on the Modules to know how to create dependencies.

Play Framework 2.4.1: How to migrate custom plugins

As of Play 2.4 the Plugin class is deprecated and one should use the Module class instead.
I've understood file play.plugins is no longer necessary and custom modules should be registered in application.conf as documented here.
But how do I migrate my old plugins? The Module class doesn't contain methods onStart and onStop... Is there an example somewhere?
This pull request has the full Redis plugin migration from 2.3 to 2.4. They use the constructor for the onStart and ApplicationLifecycle for the onStop in SedisPoolProvider.
https://github.com/typesafehub/play-plugins/pull/148/files
Documentation explains that the goal is to provide bindings in a DI framework agnostic way. This is the reason I believe there is no trait with onStart and onStop to implement. The agnostic way is to use constructor and/or by injecting a lifecycle module like ApplicationLifecycle.

Using the ServiceLocator in ZF2 with Doctrine 2 from/in a Custom Class?

i have a little problem using doctrine 2 in Zend Framework 2 i have custome class that i use to manipulate doctrine generated model (basically to inject data and populate), to make that work i need the entity manager which is available through the service manager as indicated in Jason Grimes tutorial here http://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/.
In his tutorial it works (i tested it) as the ServiceLocator is called from a controller class, but for the application i am writing i have to use custom (non controller) classes to interact with the entities. How do i achieve this? Using the servicelocator from a custom class that is not a controller? Thank you all in advance
You need to do two steps
Implement Zend\ServiceManager\ServiceLocatorAwareInterface in your custom class. This allows to the Framework to inject the Service Locator for you.
Convert your custom class to a service and retrieve it using Service Manager. This component will check if the class implement ServiceLocatorAwareInterface and the inject the ServiceLocator before returning to you the instance

How to provide ASP.NET MVC2 master pages with a model indepdent of the controller

I'm using strongly typed views and autofac for Dependency Injection under ASP.NET MVC2 and I'm trying to get a common dynamic header via dependency injection. I.e. i want this to happen without the view having to be away of this content even existing and i was hoping to avoid static discovery of the container and manual resolution, but I can't find a way to easily inject the master or a partial view included in the master via either ctor or property injection.
I can't imagine this is an uncommon task, but all I can find in terms of methods is Controller subclassing to stuff data into untyped ViewData, subclassing ViewModels to stuff master data into the model, or static resolution, all of which I'd prefer not to use. What am I overlooking?
EDIT: As has been pointed out DI into master pages is fighting the framework. So my question is badly framed: I don't really care about DI into master pages, but I have a dynamic element in the chrome of the site, i.e. the master page. Providing it with a model shouldn't be the responsibility of each controller using that master, as it is request context, not controller context specific. I fully admit that injection directly into master pages is inappropriate. If i could register a separate master controller to be invoked in addition, that would be even better. Is that possible? Given this task of providing the master with a model independent of the controller, what is the framework appropriate approach? Or does shared content in MVC require that each Controller has to know about that content?
You could use child actions.
Controller:
public class MyHeaderController: Controller
{
private readony IRepository _repository;
public MyHeaderController(IRepository repository)
{
_repository = repository;
}
[ChildActionOnly]
public ActionResult Index()
{
var model = _repository.GetSomeModel();
return PartialView(model);
}
}
And somewhere in your master page include it:
<div><%= Html.Action("Index", "MyHeader") %></div>
Your problems stem from confusing the term Dependency Injection, and fighting how the ASP.NET MVC framework works.
Also, you are using the term Dependency Injection in the wrong context. You are trying to use a hammer as a chisel.
MasterPages and views in ASP.NET MVC are intended to be used as templates. As stated in the other answer, child actions will solve your problem.
For future reference:
Dependency Injection refers to a means to configure what parameters to inject into class constructors, and have this done for you automatically, overriding some of the frameworks defaults. The purpose for this is to decouple components, so that they become more reusable, more testable, more unitary, amongst other good things.
DI refers to, and solves, a code issue, not a UI issue.
What you are trying to do is simply not possible. Ie, inject via constructors and properties a "dependency" into a masterpage. Again, MasterPages are intended by ASP.NET MVC to be used as just templates. They have no code behind class to instantiate via a constructor that would allow dependencies to be injected into it.
In other words, you are fighting the framework, which means you don't understand it.
If this sounds like nitpicking, I think this has to be highlighted as otherwise, you are confusing yourself and others who read this thread in the future.

setter injection guice + wicket

I have a Wicket Web Page where I create a new Object of class A:
A a = new A(User u);
In A I would like to have setter injection, however this is actually not done. I have heard that one must provide an empty constructor but how is it possible to have also a non - empty constructor with setter injection?
I'm not familiar with Wicket, but I assume that you've got various things on your Wicket web page annotated with #Inject, yes?
So, you have a few options; in order of preference:
If you're #Injecting your User, one option is to annotate the constructor of A with #Inject and then in your page, just #Inject either an A or a Provider<A> into web page.
You can #Inject into your web page a MembersInjector<A> (call it aMembersInjector) and then after you create your A object call aMembersInjector.injectMembers(a) to cause all the setter injection to happen.
You can #Inject into your web page the Injector and call Injector.injectMembers(a) after you create your A.
I'm not exactly sure what you're asking. Regardless, try taking a look at
This question
Wicket Spring integration
Wicket Guice integration
at see if any examples there shed light on your problem.