Exemplo n.º 1
0
        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));
            });
        }