return Null Form in casting with ServiceProvider

gaiusonesimus

New member
Joined
Jul 8, 2018
Messages
1
Programming Experience
1-3
I have the code below. the form return a null. What code should I write to prevent returning a form into null? or how can I add the form into ServiceProvider?

C#:
        private static IServiceProvider ServiceProvider { get; set; }
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var services = new ServiceCollection();

            services.AddScoped<IEntityService, IEntityService>();
            ServiceProvider = services.BuildServiceProvider();

            var form = (MainForm)ServiceProvider.GetService(typeof(MainForm));

            Application.Run(form);
        }
 
Back
Top Bottom