Unable to inject schema when using more than one schema in Dependecy Injection.
myteam-vishnu opened this issue · comments
Hi all,
Here, i am having a problem with Ischema, When i am using ISchema i need to define type of that but problem occurs when need to use multiple schema as we can define one schema type only at a time.
Here, i am sharing code with you.
private ISimpleContainer BuildContainer()
{
var container = new SimpleContainer();
container.Singleton(new DocumentExecuter());
container.Singleton(new DocumentWriter(true));
container.Singleton(new StarWarsData());
container.Register<StarWarsQuery>();
container.Register<StarWarsMutation>();
container.Register<HumanType>();
container.Register<HumanInputType>();
container.Register<DroidType>();
container.Register<CharacterInterface>();
/*As here i am adding ISchema as type so this is calling properly but ..*/
container.Singleton<ISchema>(new StarWarsSchema(new FuncDependencyResolver(type =>
container.Get(type))));
/*When need to add another one then it is not calling let alone get executed...*/
container.Singleton<ISchema>(new EpisodeSchema(new FuncDependencyResolver(type =>
container.Get(type))));
// following is the error, i am getting while executing this code...
// Dictionary can not add multiple instnace of ISchema.
return container;
}
thanks
If you need more than one Schema, then you can’t use a singleton. A singleton means there is only a single instance of that type. I suggest to read the documentation of the container you’re using and reach out to that project to know how to structure your classes with that container.