I have a request service and I want to get tenant's address with its id. So I need TenantAppService in another service. I can't pass it from javascript, because it is an object and I think ajax converts my parameters to url. Do I need to serialize it or can I create an instance of TenantAppService in my service? Is there an applicable constructor?
Or can I use stored procedure? I tried it but even though i imported
using System.Data.SqlClient;
SqlConnection could not be found.
Related
I am working on Webhooks Concept. Since Webhooks acts like a trigger, it will be firing an event when Update or Insert takes place.
It's a MVC application and I have two Controllers, Home and Webhook Controller.
I am passing arguments through Query String on Home controller.
I have tried Session, TempData and Cookies for passing variable from home to Webhooks
HttpContext.Session.SetString("UserName", Request.Query["UserName"].ToString());
and getting session value on webhook controller
HttpContext.Session.GetString("UserName");
Also tried the same for TempData
Issue is On webbooks Controller its coming null.
I need to store parameter (User Name ,password) and reuse the same for database related operations.
Kindly guide
As far as I know, if you store the data into the cookie, session or TempData, it will always use the cookie. But you said the Webhook should worked as a trigger.
I guess this trigger is not triggered by the request or not. It was triggered by some application method. Since it doesn't contain the cookie ID which is used to get the session, cookie, TempData value.
I suggest you could use some database to store it, for example Redis, Service Bus.
If your data volume is not very large, I suggest you could consider using the memory cache, by using this , you could store these things into the memory and use it.
Notice: If your data is very large, I suggest you could use redis or service bus instead.
I seem to have a circular dependency where we have a service provider that registers an object with the service container, and boots a config file and some middleware, but the middleware now needs to be passed a param parsed from requests JWT token to the service container prior to it being instantiated, as well as the guard of the user since the service provider needs to be able to get the authenticated user and there are 5 different types (Applicant, Manager, Admin, etc) so the guard is needed to Auth::guard($guard)->getUser() within the constructor since it defaults to the Applicant if null like Auth::guard()->getUser().
How do you work around something like this? If it helps I'm using tymons/JWTAuth (develop) branch to make use of Laravel's guard API.
Should I refactor and just bind to the service container directly within the middleware and not use a service provider at all so I can use the parameter to instantiate the service container object, and the guard. Seems like the only likely solution, but before I refactor all of this I wanted to ask if there was a better way.
Can I use two service providers? One that adds middleware, and a deferred one that will somehow eventually register an object with the service container??? If so how would you pass the parameter in a config? Thinking this isn't possible based on what I know.
Adding a setter to the object isn't an option to prevent anyone accidentally invoking it anywhere else.
Are you using tymon/jwt-auth? If so, your service provider could set up an event listener that fires when the token is decoded. Something like:
event()->listen('tymon.jwt.valid', function($user){
app()->singleton(YourInterface::class, function() use ($user){
//this will only register once your token is decoded
}
});
You could still listen for an event if you aren't using this package, then bind once that fires. This is basically the same as your option 1, but at least it keeps the code organized where you want it.
I'm implementing an authorization related DelegatingHandler where I load-up the api user (caller) profile from database. When the authorization is successful I'd like to pass this instance to the controller otherwise I'd must load it again.
Is there any way to do this without using session or rely on repository cache?
The HttpRequestMessage class contains a dictionary "Properties" that you could use to store that information. However, I am not sure if it is get persisted between the handler invocation and the controller action. Otherwise, you can try with an action filter where the action context is already created. The action context gives you access to the action arguments, where you can add an additional argument to be passed to the action.
In net6, the Properties Collection is deprecated. You should use Options instead. This post may interest you: How to migrate from HttpRequestMessage.Properties to HttpRequestMessage.Options
I want someone to tell me where to search for how to make a session between the client(s) and the server in RMI, i.e what is the name of that concept for searching purposes?
I named this the Remote Session pattern in my 2001 book.
The idea is to have a singleton RMI object, bound in the Registry, with nothing but a login() method. That method, if successful, returns a new RemoteSession object for every call, that contains the API you need for the session. RemoteSession is another remote interface of course. It also contains a logout() method, which unexports the object, and it also implements Unreferenced, as another way of terminating the session.
Each instance of RemoteSession can maintain client state, so it is a session object, and as the only way to get a RemoteSession object is via login(), it is secure to a first approximation.
I'm using a Web Service that has a endpoint of http://api.domain_a.com/ and using Visual Studio I can easily generate a proxy class to work with the service easy and simple.
But I want to create a way that users can use their own service (and access their own data, instead my own) and I wanted to know if there is a way that I can change the base URL of the Service on-the-fly.
As an example
I generate the proxy classes by adding the Web References to my project, but now, per each request I have a User Name that I will get the User Settings (witch contains their URL), how can I (if it's a possibility) tell the generated proxy that I'm using domain http://domain_b.com/api instead of the original that I used when adding the Web References?
Do I need to call the service manually? Sending and Receiving XML data? or there is a "switch" that I can use to point to the new URL?
If you're using .NET 2.0, each of those proxy classes should have a URL property. Simply update the URL property and the proxy will point to the new service.
If you're using WCF then things get a little more complicated, but not by much. You just have to change the Endpoint Address:
var service = new ServiceClient();
string url = "http://domain_b.com/api";
EndpointAddress newAddress = new EndpointAddress(url);
service.Endpoint.Address = newAddress;