Skip to content

Support ASP.NET Core 3.0 #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
HamedFathi opened this issue Mar 16, 2019 · 11 comments
Closed

Support ASP.NET Core 3.0 #92

HamedFathi opened this issue Mar 16, 2019 · 11 comments

Comments

@HamedFathi
Copy link

HamedFathi commented Mar 16, 2019

You can not define a return type for ConfigureServices in ASP.NET Core 3.0. I got an error on this.

public IServiceProvider ConfigureServices(IServiceCollection services)
{
    ...
}

Can you show me how to use you amazing IoC with ASP.NET Core 3.0 preview 3?

@dadhi
Copy link
Owner

dadhi commented Mar 16, 2019

Will try it soon. Thanks for head up.

@dadhi
Copy link
Owner

dadhi commented Mar 24, 2019

The docs for the reference:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-3.0

@HamedFathi, I don't see a problem if you don't return IServiceProvider from the ConfigureServices. Did you try it? What is the next error you have?

@HamedFathi
Copy link
Author

HamedFathi commented Mar 24, 2019

@dadhi
Yes, I tried it before, please see the following pictures:

image

image

.NET Core 3.0.100-preview3-010431

Unhandled Exception: System.NotSupportedException: ConfigureServices returning an System.IServiceProvider isn't supported.
   at Microsoft.AspNetCore.Hosting.Internal.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.Internal.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at DryIOC.Program.Main(String[] args) in C:\...\DryIOC\Program.cs:line 18

Related link:

Unable to use ConfigureTestServices with StructureMap

@dadhi
Copy link
Owner

dadhi commented Mar 24, 2019

Instead of creating the Container in your Startup, you may just move it to the host (Program.cs), and make Startup a fully IOC agnostic - see details here: #94 (comment)

In addition, DryIocServiceProviderFactory has couple of optional parameters if you need some customization.

@HamedFathi
Copy link
Author

I revert all configs in Startup.cs except AddControllersAsServices
image

And in Program.cs

image

Could not load file or assembly 'DryIoc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=dfbf2bd50fcf7768'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

@dadhi
Copy link
Owner

dadhi commented Mar 24, 2019

This is strange, could you share this sample application with me?

@HamedFathi
Copy link
Author

Sure, You can find it here

@dadhi
Copy link
Owner

dadhi commented Mar 29, 2019

I tried to build the sample in vs2019 and .NET Core 3 preview 3, and after some quirks got the same error.

Not sure the reason, but it shoud not relate to DryIoc itself. DryIoc is strongly signed now, is it a problem? or is it a binding redirects? Not sure. But won't spend much time on it until RC. If you have ideas, please help.

@dadhi
Copy link
Owner

dadhi commented Mar 29, 2019

I think a possible workaroud would be the use of source code package for DryIoc.MS.DI, which is not existent. Maybe it is time to make it , hmmm...

@dadhi
Copy link
Owner

dadhi commented Mar 30, 2019

I have published DryIoc.Microsoft.DependencyInjection.src source package and will try it.

@dadhi
Copy link
Owner

dadhi commented Mar 31, 2019

Puzzle solved:

image

The problem was that the sample project has the same name as the transient dependency (DryIoc).

@dadhi dadhi closed this as completed Mar 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants