﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Stratis.Bitcoin.Miner;
using Stratis.Bitcoin.RPC.ModelBinders;
using Stratis.Bitcoin.Wallet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Stratis.Bitcoin.RPC
{
    public static class WebHostExtensions
    {
        public static IWebHostBuilder ForFullNode(this IWebHostBuilder hostBuilder, FullNode fullNode)
        {
            hostBuilder.ConfigureServices(s =>
            {
                s.AddMvcCore(o =>
                {
                    o.ModelBinderProviders.Insert(0, new DestinationModelBinder());
                    o.ModelBinderProviders.Insert(0, new MoneyModelBinder());
                });
                s.AddSingleton(fullNode);
                s.AddSingleton(fullNode as Builder.IFullNode);
                s.AddSingleton(fullNode.Network);
                s.AddSingleton(fullNode.Settings);
                s.AddSingleton(fullNode.ConsensusLoop);
                s.AddSingleton(fullNode.ConsensusLoop?.Validator);
                s.AddSingleton(fullNode.Chain);
                s.AddSingleton(fullNode.ChainBehaviorState);
                s.AddSingleton(fullNode.BlockStoreManager);
                s.AddSingleton(fullNode.MempoolManager);
                s.AddSingleton(fullNode.ConnectionManager);
                s.AddSingleton(fullNode.Services.ServiceProvider.GetService<IWalletManager>());
                var pow = fullNode.Services.ServiceProvider.GetService<PowMining>();
                if(pow != null)
                    s.AddSingleton(pow);
            });
            return hostBuilder;
        }
    }
}

﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Stratis.Bitcoin.Miner;
using Stratis.Bitcoin.RPC.ModelBinders;
using Stratis.Bitcoin.Wallet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Stratis.Bitcoin.RPC
{
    public static class WebHostExtensions
    {
        public static IWebHostBuilder ForFullNode(this IWebHostBuilder hostBuilder, FullNode fullNode)
        {
            hostBuilder.ConfigureServices(s =>
            {
                s.AddMvcCore(o =>
                {
                    o.ModelBinderProviders.Insert(0, new DestinationModelBinder());
                    o.ModelBinderProviders.Insert(0, new MoneyModelBinder());
                });
            });

            return hostBuilder;
        }
    }
}

Remove manual DI configuration for node in RPC
Remove manual DI configuration for node in RPC

DI for RPC now automatically adds full node DI to its DI container.
This is done in RPCFeature on startup.
