Skip to content
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

How to tell if there is an instance of a class exported? #294

Open
XanNava opened this issue Jul 28, 2022 · 1 comment
Open

How to tell if there is an instance of a class exported? #294

XanNava opened this issue Jul 28, 2022 · 1 comment

Comments

@XanNava
Copy link

XanNava commented Jul 28, 2022

So I was trying to do a conditional check(to see if a class was exported) for null off of container.Locate() but it was creating a new instance of that class when I called it(even though the Type hasn't been exported yet). Would I call keys and then check off the Type to see if a key exists for the Type I want to add?

@ipjohnson
Copy link
Owner

I'm assuming the type you were testing for was a class and not an interface. The container will auto resolve concrete classes. You can turn the feature off like this.

var container = new DependencyInjectionContainer(c => c.AutoRegisterUnknown = false);

The other option would be to look at the container.StrategyCollectionContainer collection and test if your type has been registered.

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