dadhi / DryIoc

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

was there something wrong make by me (RegisterMany) ? #517

Closed sgf closed 2 years ago

sgf commented 2 years ago

图片

I refer to this example: https://stackoverflow.com/questions/42368192/dryioc-registermany-implementations-of-interface by the way.DryIoc's API design looks little complex,not easy to use.

dadhi commented 2 years ago

@sgf The exception is saying it all. In the provided asms there are no legit service types. It may mean that you don't have the types at all or no public types. In the later case, if you want to register non-public types, then you need to pass nonPublicServiceTypes: true to RegisterMany (btw, the exception message has this information as well).

Regarding complexity, if you are manipulating assemblies, you are already on the complex ground... I don't see how container.RegisterMany(new[] { typeof(A).Assembly }, serviceTypeCondition: type => type == typeof(X)); makes it harder, but I am open for suggestions.

sgf commented 2 years ago

i think,maybe the reason is what types i want to register is winform UseControl. maybe because it's Implementation of IDisposable.

sgf commented 2 years ago

@sgf The exception is saying it all. In the provided asms there are no legit service types. It may mean that you don't have the types at all or no public types. In the later case, if you want to register non-public types, then you need to pass nonPublicServiceTypes: true to RegisterMany (btw, the exception message has this information as well).

Regarding complexity, if you are manipulating assemblies, you are already on the complex ground... I don't see how container.RegisterMany(new[] { typeof(A).Assembly }, serviceTypeCondition: type => type == typeof(X)); makes it harder, but I am open for suggestions.

thank,you