ReactJS.NET - Bundles - TinyIoCResolutionException: Unable to resolve type: React.IReactEnvironment

后端 未结 3 2244
心在旅途
心在旅途 2020-12-20 17:12

I\'m attempting to minify my .JSX files with ASP.NET Minification and Optimization via System.Web.Optimization.React. I\'ve installed the MVC4 React Package as well as the O

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-20 18:00

    I'm not sure if this is the same issue I was facing, but I googled the exact same error, found this SO topic as the first hit, with no definitive answer, so I thought I'd offer my solution.


    I'm using .NET 4.5 in an MVC app, and React.Web.Mvc4 v3.0.0.

    I managed to work around this issue with the help of this comment on Github.

    Here's my entire ReactConfig.cs:

    using React;
    using React.TinyIoC;
    using React.Web.TinyIoC;
    
    namespace NS.Project
    {
        public static class ReactConfig
        {
            public static void Configure()
            {
                Initializer.Initialize(AsPerRequestSingleton);
    
                ReactSiteConfiguration.Configuration
                    .SetLoadBabel(false)
                    .AddScriptWithoutTransform("~/React/dist/server.bundle.js");
            }
    
            private static TinyIoCContainer.RegisterOptions AsPerRequestSingleton(
                TinyIoCContainer.RegisterOptions registerOptions)
            {
                return TinyIoCContainer.RegisterOptions.ToCustomLifetimeManager(
                    registerOptions,
                    new HttpContextLifetimeProvider(),
                    "per request singleton"
                );
            }
        }
    }
    

    Then, I'm callingReactConfig.Configure explicitly from Application_Start.

提交回复
热议问题