dependency-injection

How and when to dispose my objects?

走远了吗. 提交于 2020-12-27 03:14:45
问题 In my backend service I use unit of work pattern. I was wondering if I'm missing something related to disposing objects. First, this is the code I have so far, which works. The service just calls a request handler: [GlobalExceptionHandlerBehaviour(typeof(GlobalExceptionHandler))] public class CustomerService : ICustomerService { public void AddCustomer(AddCustomerRequest request) { ObjectFactory.GetInstance<AddCustomerRequestHandler>().Execute(request); } } The request handler looks like:

How and when to dispose my objects?

a 夏天 提交于 2020-12-27 03:13:07
问题 In my backend service I use unit of work pattern. I was wondering if I'm missing something related to disposing objects. First, this is the code I have so far, which works. The service just calls a request handler: [GlobalExceptionHandlerBehaviour(typeof(GlobalExceptionHandler))] public class CustomerService : ICustomerService { public void AddCustomer(AddCustomerRequest request) { ObjectFactory.GetInstance<AddCustomerRequestHandler>().Execute(request); } } The request handler looks like:

Binding a guava supplier using guice

一笑奈何 提交于 2020-12-26 11:04:50
问题 I want do a binding like this, bind(Supplier<TestClass>).toProvider(Provider<Supplier<TestClass>>).in(Singleton.class); The provider is returned by an external function so, inside the toProvider() , I call that function and it returns Provider <Supplier<TestClass>> . The supplier is from guava, the reason to do this kind of thing is, there is a file associated with the TestClass and I need to read that file and assign those values to the respective fields of TestClass. And that file change at

Static class to dependency injection

落花浮王杯 提交于 2020-12-25 04:02:29
问题 The application I'm trying to get to work uses MVVM. The biggest part of this post is an explanation of what I tried and what I got working. The question is near the bottom of the post. The used Localizer class is only used here as an example and can easily be replaced with another class. I have a class library with a Localizer class. This purpose of this class is to change the language of the application on the fly, without having to restart the application. The `Localizer has to be

How can we handle more than one user usage for identity core usermanagement and userstore without customization with generic type?

两盒软妹~` 提交于 2020-12-15 03:56:20
问题 We have a multitenant architecture with more than one user like below with identity core library: public class ApplicationUser : IdentityUser { } public class Tenant1User: ApplicationUser { public int deneme { get; set; } } public class Tenant2User: ApplicationUser { public string City { get; set; } public string Picture { get; set; } public DateTime? BirthDay { get; set; } public int Gender { get; set; } } We wanted to use UserManager generically in controllers constructors when injecting

Inject SignalR IHubContext into service layer with Autofac

霸气de小男生 提交于 2020-12-09 06:34:32
问题 In an app running Framework 4.72, not .NET Core, I'm trying to inject a SignalR IHubContext into a Web API 2.x service. I have my solution broken into three projects, web, service, data. The SignalR hub is in the web layer. I have background code that runs in the service layer and when complete I need it to send a mesage via the hub. This background task is not initiated by the controller. My Global.asax is pretty standard: protected void Application_Start() { GlobalConfiguration.Configure

angular multiple APP_INITIALIZER that depend on each other

蹲街弑〆低调 提交于 2020-12-08 07:58:11
问题 Background: I need to perform couple of initial checks during the application start up (1) read angular app config from ./assets/config.json file and get the API end point from there, (2) make an API call to end point retrieved in first step and load some settings from back end. Goal: be able to initialize two services using APP_INITIALIZER (say A & B), where B has a dependency on A. check out this stackblitz to see the problem Things I've tried: If second part (being able to make an API

Inject ApplicationUser in ASP.NET Core MVC

◇◆丶佛笑我妖孽 提交于 2020-12-08 07:29:24
问题 I have a class that requires ApplicationUser (from ASP.NET Identity). The instance should be the current user. public class SomeClass { public SomeClass(ApplicationUser user) { Currently, what I'm doing is I inject the current user from the Controller: var currentUser = await _userManager.GetUserAsync(User); var instance = new SomeClass(currentUser); Now I want to use Dependency Injection provided by Microsoft. I can't figure out how am I going to add ApplicationUser to the services. It

HttpClient DelegatingHandler unexpected life cycle

烂漫一生 提交于 2020-12-04 20:01:48
问题 In ASP.NET Core 2.1 app I am making REST request using HttpClient . I am using DelegatingHandler s to define some common behavior. The registration i here: private static void AddRestServiceDataClient<TTypedHttpClient, TTypedHttpClientImpl>(this IServiceCollection services) where TTypedHttpClient : class where TTypedHttpClientImpl : RestServiceDataClient, TTypedHttpClient { var httpClientBuilder = services .AddHttpClient<TTypedHttpClient, TTypedHttpClientImpl>() .AddHttpMessageHandler

HttpClient DelegatingHandler unexpected life cycle

拥有回忆 提交于 2020-12-04 19:59:14
问题 In ASP.NET Core 2.1 app I am making REST request using HttpClient . I am using DelegatingHandler s to define some common behavior. The registration i here: private static void AddRestServiceDataClient<TTypedHttpClient, TTypedHttpClientImpl>(this IServiceCollection services) where TTypedHttpClient : class where TTypedHttpClientImpl : RestServiceDataClient, TTypedHttpClient { var httpClientBuilder = services .AddHttpClient<TTypedHttpClient, TTypedHttpClientImpl>() .AddHttpMessageHandler