public async Task Ensure_Registered_Properties_Are_Injected() { var collection = new ServiceCollection(); string expectedValue = "TestValue"; string templateKey = "key"; collection.AddSingleton(new TestViewModel() { Title = expectedValue }); var propertyInjector = new PropertyInjector(collection.BuildServiceProvider()); var builder = new StringBuilder(); builder.AppendLine("@model object"); builder.AppendLine("@inject RazorLight.Tests.Models.TestViewModel test"); builder.AppendLine("Hello @test"); var engine = new EngineFactory().ForEmbeddedResources(typeof(Root)); engine.Options.DynamicTemplates.Add(templateKey, builder.ToString()); ITemplatePage templatePage = await engine.CompileTemplateAsync(templateKey); //Act propertyInjector.Inject(templatePage); //Assert var prop = templatePage.GetType().GetProperty("test").GetValue(templatePage); Assert.NotNull(prop); Assert.IsAssignableFrom <TestViewModel>(prop); Assert.Equal((prop as TestViewModel).Title, expectedValue); }