ipjohnson / Grace

Grace is a feature rich dependency injection container library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

XanNava opened this issue · comments

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?

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.