dadhi / DryIoc

DryIoc is fast, small, full-featured IoC Container for .NET
MIT License
1.03k stars 122 forks source link

Method not found: 'DryIoc.Rules DryIoc.Rules.WithoutFastExpressionCompiler() #529

Closed lwlivy closed 2 years ago

lwlivy commented 2 years ago

Version: 5.2.2

This error occurs when I use the following code. How can I solve this problem.

new DryIocContainerExtension(new Container(CreateContainerRules()) .WithDependencyInjectionAdapter(services));

dadhi commented 2 years ago

What extension are you using?

The exception means that the extension (whatever it is) expects the method WithoutFastExpressionCompiler to be present. But it was removed in DryIoc v5.

lwlivy commented 2 years ago

I want to combine IServiceCollection to inject, but it has not been successful. Now, change to this way, but an error will be reported. When I simply use IServiceCollection, it will not work properly.Did I use it wrong? Error: System.ArgumentException:“At least one object must implement IComparable.”

error location: public Repository(DbContext dbContext) { _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); _dbSet = _dbContext.Set(); }

IOC Code: containerRegistry.RegisterScoped<DbContext, LidsDbContext>(); var services = new[] { typeof(IRepositoryFactory), typeof(IUnitOfWork), typeof(IUnitOfWork) }; containerRegistry.RegisterMany<UnitOfWork>(services); //containerRegistry.RegisterScoped<IRepositoryFactory, UnitOfWork>(); //containerRegistry.RegisterScoped<IUnitOfWork, UnitOfWork>(); //containerRegistry.RegisterScoped<IUnitOfWork,UnitOfWork>(); containerRegistry.RegisterScoped(typeof(IRepository<>), typeof(Repository<>));

lwlivy commented 2 years ago

Do you have any good suggestions?

dadhi commented 2 years ago

@lwlivy I don't fully understand the question and what the problem or exception do you have. I would suggest you to ask the question on StackOverflow tagging with dryioc and provide the complete failing test, so people can understand the context.

Sharemee commented 2 years ago

@lwlivy You can see DryIoc 5.0.0 — Method not found: WithoutFastExpressionCompiler(). This issue can close. Good luck.

Tum4ik commented 1 year ago

As far as I can understand, Prism is in action here. So, you can simply override the creation of the container rules. I guess it should be in the App.xaml.cs class.

protected override Rules CreateContainerRules()
{
    return Rules.Default.WithConcreteTypeDynamicRegistrations(reuse: Reuse.Transient)
                        .With(Made.Of(FactoryMethod.ConstructorWithResolvableArguments))
                        .WithFuncAndLazyWithoutRegistration()
                        .WithTrackingDisposableTransients()
                        //.WithoutFastExpressionCompiler()
                        .WithFactorySelector(Rules.SelectLastRegisteredFactory());
}