Ninject intercept throwing error. Dynamic proxy - ninject

I have a class which I use to bootstrap.
as part of the object creation I use by convention to bind to interfaces.
All works OK until I try to add an interceptor.
public class ContainerBootstrapper : IDisposable
{
StandardKernel _c;
public ContainerBootstrapper()
{
_c =new StandardKernel();
_c.Bind(b => b.FromAssembliesMatching("Facade*.*").SelectAllClasses().BindDefaultInterfaces());
_c.Bind(b => b.FromAssembliesMatching("Object*.*").SelectAllClasses().BindDefaultInterfaces());
_c.Bind(b => b.FromAssembliesMatching("Logger*.*").SelectAllClasses().BindDefaultInterfaces());
//even using the built in ActionInterceptor like this:
_c.Intercept(c => true)
.With(new ActionInterceptor(invocation =>
Console.Write(invocation.Request.Method.Name)));
When this line is hit, I get an error - Error loading Ninject component IAdviceFactory
No such component has been registered in the kernel's component container.
Suggestions:
1) If you have created a custom subclass for KernelBase, ensure that you have properly
implemented the AddComponents() method.
2) Ensure that you have not removed the component from the container via a call to RemoveAll().
3) Ensure you have not accidentally created more than one kernel.
I have at the top:
using Ninject.Extensions.Conventions;
using Ninject.Extensions.Interception.Injection.Dynamic;
using Ninject.Extensions.Interception.Infrastructure.Language;
using Ninject.Extensions.Interception;
and used NuGet for packages. Tried both Dynamic Proxies and LinFu. Both gave same error.
Anyone have any ideas to try?
Thanks in advance.

Turns out that even though I had a reference to the project doing the bootstrapping and I thought all my dlls for ninject where being copied over automatically this was not the case. After moving them manually it worked.

Related

Sending ResetPassword notification using queue in Laravel 6 - error property 'view'

I want to override default notifications for password reset and email verification in laravel 6 to use queue in a simplest way as possible. So I add methods in User.php model:
use App\Notifications\ResetPasswordNotification;
use App\Notifications\EmailVerificationNotification;
...
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}
public function sendEmailVerificationNotification()
{
$this->notify(new EmailVerificationNotification);
}
and create new notifications
ResetPasswordNotification
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Auth\Notifications\ResetPassword;
class ResetPasswordNotification extends ResetPassword implements ShouldQueue
{
use Queueable;
}
EmailVerificationNotification
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Auth\Notifications\VerifyEmail;
class EmailVerificationNotification extends VerifyEmail implements ShouldQueue
{
use Queueable;
}
Now email verification is sending queued, but in url as a host name is generating http://localhost/... In default notification it is generated correctly, the same one like a domain name in browser (without changing it in .env file).
The second problem is with password reset notification, which is not sending at all. It gives me an error
Trying to get property 'view' of non-object at vendor/laravel/framework/src/Illuminate/Notifications/Channels/MailChannel.php:92
and I don't understand why it is happening and don't working as expected.
Searching the problem I even found this (question) where fakemeta mention about it that should work.
I figured it out. First, when using queue, in my case I am running artisan queue:work with supervisor daemon, jobs are running under the console, so there is no SERVER['HTTP_HOST'] var available which mean than this value must be read from .env file. Second, when You change code overriding methods like I did, you must restart this queue:work to re-read changes. So those were my main problems.

Two way databinding to singleton service Blazor Serverside

I have been playing with Blazor on the client using Webassembly quite a bit. But I thought I would try the serverside version now and I had a simple idea I wanted to try out.
So my understading was that Blazor serverside uses SignalR to "push" out changes so that the client re-renders a part of its page.
what I wanted to try was to databind to a property on a singleton service like this:
#page "/counter"
#inject DataService dataService
<h1>Counter</h1>
<p>Current count: #currentCount ok</p>
<p> #dataService.MyProperty </p>
<p>
#dataService.Id
</p>
<button class="btn btn-primary" #onclick="IncrementCount">Click me</button>
#code {
int currentCount = 0;
void IncrementCount()
{
currentCount++;
dataService.MyProperty += "--o--|";
}
}
Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton<WeatherForecastService>();
services.AddSingleton<DataService>();
}
Service:
namespace bl1.Services
{
public class DataService
{
public DataService()
{
this.Id = System.Guid.NewGuid().ToString();
}
public string Id {get;set;}
public string MyProperty { get; set; }
}
}
So my question is this. Why, if I open up this page in two tabs, do I not immediately see the value being updated for the property MyProperty with SignalR when I am changing the value on the property in one tab in the other tab? Is there a reason that is not supposed to work or am I just simply doing it wrong?
I thought the upside of using Blazor on the serverside was that you could easily use the fact that SignalR is available and get live updates when values change on the server.
I do get the latest value from the singleton service in the other tab but only after I click the button there.
Sorry you didn't get a better answer earlier Ashkan (I just read your question now). What you were attempting is actually something Blazor does very well and you are correct it is the perfect architecture for problems like this. Using SignalR directly, like the above answer suggested, would be correct for a Blazor WASM solution, but that doesn't address your question, which was about using Server-side Blazor. I will provide the solution below.
The important point is to understand that a blazor component does not "poll" for changes in its bound properties. Instead, a component will automatically re-render itself (to an internal tree) if say a button is clicked on that component. A diff will then be performed against the previous render, and server side blazor will only send an update to the client (browser) if there is a change.
In your case, you have a component that uses an injected singleton for its model. You then open the component in two tabs and, as expected (given Blazor's architecture), only the component in the tab where you clicked the button is re-rendering. This is because nothing is instructing the other instance of the component to re-render (and Blazor is not "polling" for changes in the property value).
What you need to do is instruct all instances of the component to re-render; and you do this by calling StateHasChanged on each component.
So the solution is to wire up each component in OnInitialized() to an event you can invoke by calling Refresh() after you modify a property value; then un-wiring it in Dispose().
You need to add this to the top of your component to correctly clean up:
#implements IDisposable
Then add this code:
static event Action OnChange;
void Refresh() => InvokeAsync(StateHasChanged);
override protected void OnInitialized() => OnChange += Refresh;
void IDisposable.Dispose() => OnChange -= Refresh;
You can move my OnChange event into your singleton rather than having it as a static.
If you call "Refresh()" you will now notice all components are instantly redrawn on any open tabs. I hope that helps.
See the documentation here
A Blazor Server app is built on top of ASP.NET Core SignalR. Each
client communicates to the server over one or more SignalR connections
called a circuit. A circuit is Blazor's abstraction over SignalR
connections that can tolerate temporary network interruptions. When a
Blazor client sees that the SignalR connection is disconnected, it
attempts to reconnect to the server using a new SignalR connection.
Each browser screen (browser tab or iframe) that is connected to a
Blazor Server app uses a SignalR connection. This is yet another
important distinction compared to typical server-rendered apps. In a
server-rendered app, opening the same app in multiple browser screens
typically doesn't translate into additional resource demands on the
server. In a Blazor Server app, each browser screen requires a
separate circuit and separate instances of component state to be
managed by the server.
Blazor considers closing a browser tab or navigating to an external
URL a graceful termination. In the event of a graceful termination,
the circuit and associated resources are immediately released. A
client may also disconnect non-gracefully, for instance due to a
network interruption. Blazor Server stores disconnected circuits for a
configurable interval to allow the client to reconnect. For more
information, see the Reconnection to the same server section.
So in your case the client in another tab is not notified of the changes made on another circuit within another ConnectionContext.
Invoking StateHasChanged() on the client should fix the problem.
For the problem you describe you better use plain SignalR, not Blazor serverside.
Just to add a little more to D. Taylor's answer:
I believe in most instances you'd want to move that OnChange action into the service.
In your services .cs you should add:
public event Action OnChange;
private void NotifyDataChanged() => OnChange?.Invoke();
private int myProperty; //field
public int MyProperty // property
{
get { return myProperty; }
set
{
myProperty= value;
NotifyDataChanged();
}
}
Every time that value is changed, it will now invoke that Action.
Now adjusting what D. Taylor did in the actual .razor file, in the #code{} section now just bind the refresh method to that Action in your service...
void Refresh() => InvokeAsync(StateHasChanged);
override protected void OnInitialized() => MyService.OnChange += Refresh;
void IDisposable.Dispose() => OnChange -= Refresh;
This should now push updates to the client!

RquireJS with Module in TypeScript

I'm studing TypeScript and RequireJS.
I want to simple module require but module type information missing.
Is there smart solution in such situation?
requirejs(['backbone'], (Backbone) => {
// In this function.
// Backbone is 'any'
});
requirejs(['backbone'], (BackboneRef: Backbone) => {
// error : Type reference cannot refer to container
// 型参照でコンテナー 'Backbone' を参照できません。
});
To do so you need to do the following:
Download backbone.d.ts from https://github.com/borisyankov/DefinitelyTyped, the backbone.d.ts provides typescript strongly-typed interface, if you use IDE like Visual Studio, you can have all the intellisense support to Backbone
(Optional) Config backbone in RequireJS
In your TypeScript class, you can reference Backbone like the following
`
/// <amd-dependency path="backbone" />;
/// <reference path="path/to//backbone.d.ts" />;
export class YourModel extends Backbone.Model {
}
The amd-dependency tells the compiler how to reference backbone, so it would generate the correct define statement in JavaScript.
The reference provides a way to Backbone's definition for typed check.
Hope this helps! TypeScript eliminates the hell of writing long define or require js statement, which can be error-prone in situation where there are lots of dependencies.

Protractor and Typescript: Class defined in different file but the same module causes 'declaration exception'

I am completely confused what I am doing wrong here.
Say I have a test file 'SimpleTest.ts' containing the following:
/// <reference path="../otherdir/simpleclass.ts" />
module MyModule.SubModule {
describe("this test", () => {
var myObject: SimpleClass = new SimpleClass("");
it("doesn't even get here!", () => {
expect(myObject).toBeDefined();
});
});
}
The class here is defined in a different file, but in the same module, like this:
module MyModule.SubModule {
export class SimpleClass {
constructor(private myMember: string) {}
}
}
So both definitions reside in the same module. Typescript compiles fine, everything looks OK.
But when I start protractor (yes, I have configured 'specs:' path to the files correctly), it stops with the error
this test
encountered a declaration exception - fail
I know that I could get it to work by using module.export and require, but this is not a good solution.
First, I loose the type checking of typescript, when I use javascript 'require', and the type checking is one of the reasons why I'm using it in the first place.
Second, I think this is bad style to mix plain javascript into typescript code.
Any help would be appreciated!
Thanks in advance,
Regards,
Jörg
Stop using internal modules.
It honestly helped me a lot when trying to understand TypeScript.
My experiences with internal TypeScript modules are answered here
.
You can read the article of Steve Fenton here for more details.
I hope this is of any help still to you.

Assigning a class to a custom stage (Puppet)

I'm working on my first Puppet file for provisioning a Vagrant setup, and I'm sort of stuck.
I'm using the RVM module to handle Ruby and RubyGem installations, but apparently they use their own custom stage called 'rvm-install' that runs BEFORE the main stage.
In order to get the dependencies for RVM installed (Package resources), I need to run them before the 'rvm-install' stage. I realized this means I need a custom stage to have run before that.
I've written this class that encompasses the things needing done...but I don't understand how to assign the class to a stage...the documentation at PuppetLabs didn't seem to cover how you're supposed to do it when you already have a block of stuff in the class.
class before-rm {
exec { "apt-get update":
command => "/usr/bin/apt-get update"
}
package { "libxml2":
ensure => present,
require => Exec['apt-get update']
}
package { "nodejs":
ensure => present,
require => Exec['apt-get update']
}
}
Any help would be greatly appreciated. This is how I've got the Stage defined in the same file:
# Custom stage!
stage { 'before-rvm':
before => Stage['rvm-install']
}
Stage['before-rvm'] -> Stage['rvm-install']
Normally you would instantiate the before-rm class like this for the main stage:
include before-rm
which is equivalent to
class { 'before-rm': }
To instantiate a class for another stage you can use the metaparameter (not a parameter of the class, of all classes in general) stage.
class { 'before-rm':
stage => before-rvm
}
Here is a link to this in the docs: http://docs.puppetlabs.com/puppet/2.7/reference/lang_run_stages.html#assigning-classes-to-stages