usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;publicinterfaceIContainer{voidRegister<TService,TImplementation>()whereTImplementation:TService;voidRegister<TService>(Func<TService>instanceCreator);TServiceResolve<TService>();}publicclassContainer:IContainer{privateDictionary<Type,Func<object>>_registry=newDictionary<Type,Func<object>>();publicvoidRegister<TService,TImplementation>()whereTImplementation:TService{_registry[typeof(TService)]=()=>Activator.CreateInstance(typeof(TImplementation));}publicvoidRegister<TService>(Func<TService>instanceCreator){_registry[typeof(TService)]=()=>instanceCreator();}publicTServiceResolve<TService>(){Func<object>creator;if(_registry.TryGetValue(typeof(TService),outcreator)){return(TService)creator();}else{thrownewException($"No registration for {typeof(TService)}");}}}