public void RegisterServices(ServiceCollection services) { services.RegisterTypeFactory <IServiceScopeFactory>(p => new ServiceScopeFactory(p)); services.RegisterScoped <IServiceScopeFactory>(); services.RegisterTypeFactory <IServiceScope>(p => new ServiceScope(p)); services.RegisterScoped <IServiceScope>(); services.RegisterTypeFactory <ServiceProvider>(p => p); services.RegisterScoped <IServiceProvider>(typeof(ServiceProvider)); services.RegisterScoped <ServiceProvider>(typeof(ServiceProvider)); services.RegisterTypeFactory <Settings>(p => new Settings()); services.RegisterSingleton <Settings>(); }
public void RegisterServices(ServiceCollection services) { services.RegisterTypeFactory <SpriteBatch>(p => new SpriteBatch(p.GetService <GraphicsDevice>())); services.RegisterTypeFactory <Camera2D>(p => new Camera2D()); services.RegisterScoped <SpriteBatch>(); services.RegisterTransient(Guppy.Constants.ServiceConfigurationKeys.TransientSpritebatch); services.RegisterScoped <Camera2D>(); services.RegisterTransient(Guppy.Constants.ServiceConfigurationKeys.TransientCamera); AssemblyHelper.AddAssembly(typeof(GraphicsDevice).Assembly); AssemblyHelper.Types.GetTypesAssignableFrom <IVertexType>().Where(t => t.IsValueType).ForEach(vt => { var primitiveBatchType = typeof(PrimitiveBatch <>).MakeGenericType(vt); services.RegisterTypeFactory(primitiveBatchType, (p, t) => ActivatorUtilities.CreateInstance(p, t)); services.RegisterSingleton(ServiceConfigurationKey.From(type: primitiveBatchType)); }); }
public static void RegisterGame( this ServiceCollection services, Type game, ServiceConfigurationKey?key = default, Func <ServiceProvider, Object> factory = default, Int32 priority = 0) { ExceptionHelper.ValidateAssignableFrom <Game>(game); factory ??= p => ActivatorUtilities.CreateInstance(p, game); services.RegisterTypeFactory( type: game, method: factory, priority: priority); services.RegisterSingleton( key: key ?? ServiceConfigurationKey.From(type: game), priority: priority, baseLookupType: typeof(Game)); }