Ninject Intercept - ninject

from what dll can i get the extension of Intercept ?
I've added Ninject.Extensions.Interception from http://github.com/danielmarbach/ninject.extensions.interception
No luck there.
Is there some sample working ?
What I need is to make an interceptor that will path through from WcfClient to WcfServer a different functions with different parameters , that way I wouldn't have to implement already implemented functions behind the WcfServer code.
So the the signature of the function I've already implemented is -
public static T InvokeService<T>(MethodInfo MethodName, Type genericType, Type BlClass, params object[] ParamList)
What it does is activates the Method by BlClass and sends to it the ParamList .
I'd like to make an Interceptor that will dynamically fill the parameters while addressing the WcfServer side .
But first how can I get access to the Intercept extension in my ninjectModule?
Thanks in advance for any help you can provide :)
p.s. Tried out :
using Ninject.Extensions.Interception;
and:
using Ninject.Core;
using Ninject.Core.Interception;

the intercept() Method is within Ninject.Extensions.Interception.Infrastructure.Language.
I had trouble myself to find it.

All of the ninject projects are under http://github.com/ninject
You can find the latest pre-built binaries on our CI server at CodeBetter.com. In order to extend the interception mechanism, you need to reference the Ninject.Extensions.Interception dll and implement the IInterceptor interface or extend the SimpleInterceptor class.
-Ian

Related

Jax-rs URI call

I'm using HttpClient to access some api(Kubernetes) but I want to switch to jax-rs. Can the same functionality be achieved from Jax-rs? I was accessing the APIs in a java function. I'm a newbie to jax-rs and so far I know that it's use to create APIs.
Any help would be appreciable.
https://docs.oracle.com/javaee/7/api/javax/ws/rs/client/package-summary.html is the package summary for the javax.ws.rs.client package. with examples and directions below. Basically,
use a ClientBuilder to get a Client (with heavyweight/common stuff
like http/https parameters)
Create a WebTarget to denote an endpoint (including template placeholders)
Resolve that target (to get another WebTarget) with parameters
Invoke it to get and process the results (comes back in a Response object)

What is the purpose of ApplicationBuilder.Properties?

What is the purpose of the ApplicationBuilder.Properties collection? Why not simply use HttpContext.Items?
About the only thing I can come up with is if you want to pass objects from one piece of middleware to another, but again, you could just as easily use HttpContext.Items for that.
I suppose there is an argument for reducing scope.. if an object is only of use for middleware, why pollute HttpContext.Items?
Back in the Owin days, we would use Owin properties, and you could get these properties in your app by using GetOwinContext(), but there doesn't seem to be any equivalent of that in the asp.net middleware. So that doesn't seem like it holds the answer.
I did some searching through the framework and couldn't find anything using it within the framework itself. I might have missed something though.
Any ideas?
What is the purpose of ApplicationBuilder.Properties?
According to source code on Github
/// <summary>
/// Gets a key/value collection that can be used to share data between middleware.
/// </summary>
IDictionary<string, object> Properties { get; }
to speculate about anything else would be primarily opinion-based.

WCF Callback implementation function never gets called

I am designing a WCF service with callback, but my implementation of the callback function never gets called. And I am confused about the generated service proxy, so please help.
Here is the scenario: in the server side, I defined the service interface IMyService and callback interface IMyServiceCallback, I also implemented the IMyService in the server project. Besides the server project, I surely have another client project, to which I added the service reference in VS. And I implemented the IMyServiceCallback interface on the client side. So here comes the problem: when I am debugging it, the function never goes into my implementation of IMyServiceCallback and of course the desired result never comes out.
And this is I where I got confused: when I added the service reference in the client side, it actually generated three interfaces on the local: IMyService, IMyServiceCallback, and IMyServiceChannel plus the client proxy class. And in my local implementation of IMyServiceCallback, I declared the class to implement the local IMyServiceCallback interface, not the one from service side. Could this be the problem? Why is there two declarations of the interface under different projects(and hence different namespaces)? The reason I implement the client side interface is, if I implemented from the server side interface, it would give the error: "InstanceContext provided to the ChannelFactory contains a UserObject that does not implement the CallbackContractType error" when I tried to call the service. And another confusing part is, on the server side if I declare the callback interface name as IMyCallback, or anything else, instead of IMyServiceCallback, the generated interface on the client side would still be IMyServiceCallback, which is the name of the service interface plus the suffix "Callback". And in this situation I also got the "InstanceContext provided to the ChannelFactory contains a UserObject that does not implement the CallbackContractType error".
I guess there is something that I misunderstood about the "add service reference" and how I should implement the interface(which one to implement). Could anyone help me? Thanks!
Updated:
I somehow fixed the problem. Firstly, the two declarations is fine is desired. The local client will need to implement the local interface, which is generated when adding the service reference. And my problem was that I also defined a DataContract but the generated reference file didn't have it. It could either because I had added the assembly of the service project as reference(somebody said in this case add service reference will not generate the Datacontract) or because I was missing DataMember attribute. But anyway, after I fixed both parts, the function is working now.
When you "Add Service Reference" and generate a proxy, it is totally separate from your service implementation. Remember, you may be consuming a service that you have not written and do not have access to the service source code.
The client code should use the client generated interfaces. If you change your service, you need to regenerate the proxy.
If you find this too messy, and you know you will always control both ends, you can share the service interfaces in a common assembly and generate a proxy class at runtime using DuplexChannelFactory.CreateChannel().
As for your problem, I can only assume you are not registering your callback properly. This is covered here.
if you want publish , you must implement IMyServiceCallback and IMyService together in same project.
if only subscribe , you must implement IMyServiceCallback interface
I fixed the issue when my callback instruction was embedded in a function call.
I learned that placing the callback in just a method that does not return a result works fine.
However, when the callback instruction is placed within a function I ran into timeout issue.
I resolved it by using a backgroundworker thread within the function being invoked:
public static IMyServiceCallback Callback;
.
.
.
TaskStateData taskStateData = GetSomeData();
BackgroundWorker backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += (se, ev) =>
{
Tuple<OperationContext, TaskStateData> data = ev.Argument as Tuple<OperationContext, TaskStateData>;
var operationContext = data.Item1;
if (operationContext != null)
{
Callback = operationContext.GetCallbackChannel<IMyServiceCallback>();
Callback.OnCallBack();
}
};
Tuple<OperationContext, TaskStateData> payload = new Tuple<OperationContext, TaskStateData>(OperationContext.Current, taskStateData);
backgroundWorker.RunWorkerAsync(payload);

Ninject not creating a new instance with constructor arguments in WCF

Here is the scenario. I have a WCF service, when this service is called it passes control to an instance of another class (created via Ninject). In that class I need to do some work, specifically with Entity Framework and repositories. To cut a long story short, I have the following binding declared.
Bind<IGenericProductRepository>()
.To<GenericProductRepository>()
.WithConstructorArgument( "context", new StagingDataContext());
When I want to use this repository I have the following.
using (var genericProductRepository = IoC.Resolve<IGenericProductRepository>())
The problem is, that I only get a new instance of genericProductRepository if it's a brand new request, if the method is called multiple times in the same request I get an error stating that the context (the EF context) is already disposed, this is because it seems like I am getting the same instance back that was already disposed in the using statement. To explain it another way, using the Microsoft WCF Test Client, if I invoke it the first time, the code runs fine, if I push the invoke button again (without restarting the test client, i.e. the same request) then it throws this error about it being disposed already.
I have tried to play around with the various "scopes" that come with Ninject, but clearly I am missing something.
So my basic question is, how do I get a new repository whenever it hits that line, instead of using the same one ? Help would be greatly appreciated, I'm really trying to push for my company to adopt Ninject and drop Spring.
Look at your binding again. Even without any knowledge about Ninject you should notice that the instance of your context is created exactly once at the time the binding is defined. But what you want is have a new context on every resolve. Best it is done by not using WithConstructorArgument and let Ninject create the instance. Therefore you have to define a additional binding for the type of context. If this is not possible for some reason you have to use the lazy version of WithConstructorArgument
WithConstructorArgument("context", ctx => new StagingDataContext())
Furthermore, you might want to try The WCF extension for Ninject:
https://github.com/ninject/ninject.extensions.wcf
That way you can get rid of the ServiceLocator like usage.

What is client base class , how to use it?

I am just curious to know that what is ClientBase class in WCF, and how can i use it.
I surfed the internet and i found that this class is used to create proxies to call service methods , but no example.
Please anyone explain it with example , it will help me undestand this class...
It's the base class for your client proxies being generated by either "Add Service Reference", the svcutil.exe command line utility, or by your custom code if you don't want to use any of those methods.
It's a generic type that takes the generated client-copy of the service contract as its type parameter.
It can be extended, if you wish to do so - e.g. see IDesign's download page for a few samples of what can be done, things like:
AsyncClientBase for safe asynchronous calls
HeaderClientBase for simplified support of custom headers in your messages
Marc
It's there for autogenerated proxies which are created when service references are added to your project, not really for your own use.