The requested service 'Microsoft.AspNetCore.Hosting.Server.IServer' has not been registered - autofac

After updating to .net core 2.2 we have the following issue:
Autofac.Core.Registration.ComponentNotRegisteredException: 'The
requested service 'Microsoft.AspNetCore.Hosting.Server.IServer' has
not been registered. To avoid this exception, either register a
component to provide the service, check for service registration using
IsRegistered(), or use the ResolveOptional() method to resolve an
optional dependency.'
We are using preBuilder.Populate(services);.
Any ideas?
Thanks for your help

I had the same problem when following Microsoft migration guide for migrating from Core 2.1 to 2.2.
The problem might occur if you are not using WebHost.CreateDefaultBuilder to create the default web host builder, and you change in the CreateWebHostBuilder method of the Program class to call ConfigureKestrel instead of UseKestrel, as suggested in the migration guide.
As far as I understand if you use WebHost.CreateDefaultBuilder to create the default web host builder, it already calls UseKestrel which registers the IServer service. But you might get into some conflicts if also using UseIIS, so to avoid this problems there is a new ConfigureKestrel call that does not register the IServer. So I think that if you are not using WebHost.CreateDefaultBuilder then you still need to call UseKestrel or UseIIS explicitly.
Of course it might be something else that is causing the problems in your case, but I suspect that following the migration guide blindly (as I did) could cause problems for many developers out there.

Related

Get Identity Server 4 user data from other application

At my job we're gradually replacing a monolithic legacy system with a microservices architecture. I've been tasked with writing an auth server using Asp.Net Core, Identity Server 4 and Entity Framework*. The legacy system already has auth and our deadline is approaching, so we're going to use the legacy system as a backend for the time being.
How can I set up Identity Server/Entity Framework to pull login info through the legacy system? So far, everything I've found involves adding a database like SQL server. Assume for the sake of argument I'm not able to pull data directly from the MySQL database that the legacy system uses, but it is easy to get the user data via a JSON API.
I have written a DbContext and an implementation of IProfileService which uses it, but I'm not sure how to actually pull the users in the DbContext, and when I try to sign in from a client I get this error:
No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext.
However I haven't been able to find/figure out what to put in DbContext.OnConfiguring to set this up. I suppose I need to implement IServiceProvider somewhere, but can't find any details of how to do so.
*We're not married to these so suggestions for something more appropriate are welcome. We are using .Net Core.
The EF bit seems like a red herring here. If you're talking to an API in a legacy system then you won't use EF for that at all.
If using IdentityServer4 then it makes sense to use their EF implementations for the configuration and operational stores and then implement your sign in UI, IClaimsService etc using the API exposed by your existing system. To do that just create a simple client implementation that calls said API and accepts and returns whatever models you require.

[Castle.DynamicProxy]The created proxy object does not have properties of original object set correctly

I'm new here and hope my first question does not confuse anyone.
I am using Castle Windsor and Castle DynamicProxy together, in order to integrate AOP with IOC, so that I can implement a logging service (and auditing, etc.) with will intercept all services in my project.
I'm trying to proxy the resolved instance to get this done but with no luck. Because the proxy returned will have the properties of the resolved instance set to null. Following is the debugging info for reference (the PROBLEMATIC property is TimeService).
the resolved instance before proxied
The resolved instance before proxied.
the proxied object
The proxied object
Did I miss something or did i understand Castle DynamicProxy in a wrong way? I did search for any solutions but had no luck.
Any answers is highly appreciated. Thanks in advance.
You should use Windsor's built-in support for AOP during registration, not overriding WindsorContainer.Resolve otherwise you'll also run into other problems around releasing components and container lifetimes:
container.Register(
Component.For<ICalcService>()
.Interceptors(InterceptorReference.ForType<ReturnDefaultInterceptor>()).Last,
Component.For<ReturnDefaultInterceptor>()
);
See the docs for more info: https://github.com/castleproject/Windsor/blob/master/docs/registering-interceptors-and-proxyoptions.md

What replacement for Service Fabric's IReliableStateManager.TryAddStateSerializer<T>?

Using the latest Service Fabric SDK, we would like to replace the restrictive DataContractSerializer with a custom IStateSerializer that uses JSON serialization. We have found the IReliableStateManager.TryAddStateSerializer method, however it is marked as obsolete.
How else can we register a custom IStateSerializer?
There's no alternative way. Using it in this way is supported, but the way it works will change somewhere in the future. You should make the call based on whether you're prepared to deal with that uncertainty.

Using tapestry-jpa just with tapestry-ioc in non-web project

this is a very basic question, and I'm kind of sorry, but I don't seem to be able to get a simple Tapestry-IOC based application to work with the built-in Tapestry JPA module.
The application is not necessarily meant as a web project so the dependencies are just tapestry-ioc and tapestry-jpa for the JPA integration. I used the hibernate-entitymanager before and everything worked fine. But I thought I might rather use the official JPA support of Tapestry.
So what I did was to get the above mentioned dependencies (in Tapestry version 5.3.7) and to write the beginning of a test.
This beginning looks like this
Registry registry = RegistryBuilder.buildAndStartupRegistry(MyModule.class);
EntityManager em = registry.getService(EntityManager.class);
That's all. Because as soon as I try this I get the error that no service would implement the EntityManager interface.
So I added the Tapestry JPA module:
Registry registry = RegistryBuilder.buildAndStartupRegistry(MyModule.class, JpaModule.class);
But then again I get an error that the JpaModule wants to contribute to the ApplicationStatePersistenceStrategySource service which is not present. This service seems to be defined in the TapestryModule so I did
Registry registry = RegistryBuilder.buildAndStartupRegistry(MyModule.class, JpaModule.class, TapestryModule.class);
But this causes an error due to the missing servlet API. So now I get to the point where I would have to define the web environment for Tapestry. But I don't want this, I just wanted to use the JPA integration.
Is this even possible? And if so, how do I do it? Following the documentation at http://tapestry.apache.org/integrating-with-jpa.html does not help in this regard.
Thank you very much for reading, any hint appreciated!
Quick answer -- I could be wrong -- but I thought Tapestry-jpa was intended for using JPA with Tapestry-core (the web framework). I don't think there would be any benefit over plain JPA in your case.

Unity 2.0 Interception and MethodInvocation.Arguments

On an asp.net mvc 2 app, I'm using Unity 2.0 interception app for various types of logging where every log entry requires the id of the current user.
Currently I'm passing the User object as an argument to service and repository methods. The only reason I'm doing this is so that it's available on MethodInvocation.Argumants for the intercepted method. Ideally, I'd like to supply the interceptor with a User object somehow. This doesn't seem to be possible. Does anybody know if it is or if any other .net AOP tool provides this? I also remember this being a problem several years ago on a project using Spring/Java so I guess it is a common problem that hopefully someone has solved?
I worked it out.
To handle the intercepted calls, you have to supply an implementation of ICallHandler.
Add a User parameter to the implementation's constructor.