using System;
using System. Reflection;
namespace ConsoleApp2
{
class Program
{
static void Main ( string [ ] args)
{
ITank tank = new HeavyTank ( ) ;
var t = tank. GetType ( ) ;
object o = Activator. CreateInstance ( t) ;
MethodInfo fireMi = t. GetMethod ( "Fire" ) ;
MethodInfo runMi = t. GetMethod ( "Run" ) ;
fireMi. Invoke ( o, null ) ;
runMi. Invoke ( o, null ) ;
}
}
class Driver
{
private IVehicle _vehicle;
public Driver ( IVehicle vehicle)
{
_vehicle = vehicle;
}
public void Drive ( )
{
_vehicle. Run ( ) ;
}
}
interface IVehicle
{
void Run ( ) ;
}
class Car : IVehicle
{
public void Run ( )
{
Console. WriteLine ( "Car is running..." ) ;
}
}
class Truck : IVehicle
{
public void Run ( )
{
Console. WriteLine ( "Truck is running..." ) ;
}
}
interface IWeapon
{
void Fire ( ) ;
}
interface ITank : IVehicle , IWeapon
{
}
class LightTank : ITank
{
public void Fire ( )
{
Console. WriteLine ( "Boom!" ) ;
}
public void Run ( )
{
Console. WriteLine ( "LightTank Run..." ) ;
}
}
class MediumTank : ITank
{
public void Fire ( )
{
Console. WriteLine ( "Boom!" ) ;
}
public void Run ( )
{
Console. WriteLine ( "MediumTank!!! Run..." ) ;
}
}
class HeavyTank : ITank
{
public void Fire ( )
{
Console. WriteLine ( "Boom!" ) ;
}
public void Run ( )
{
Console. WriteLine ( "HeavyTank!!! Run..." ) ;
}
}
}
using System;
using System. Reflection;
using Microsoft. Extensions. DependencyInjection;
namespace ConsoleApp2
{
class Program
{
static void Main ( string [ ] args)
{
var sc = new ServiceCollection ( ) ;
sc. AddScoped ( typeof ( ITank) , typeof ( MediumTank) ) ;
var sp = sc. BuildServiceProvider ( ) ;
ITank tank = sp. GetService < ITank > ( ) ;
tank. Fire ( ) ;
tank. Run ( ) ;
}
}
class Driver
{
private IVehicle _vehicle;
public Driver ( IVehicle vehicle)
{
_vehicle = vehicle;
}
public void Drive ( )
{
_vehicle. Run ( ) ;
}
}
interface IVehicle
{
void Run ( ) ;
}
class Car : IVehicle
{
public void Run ( )
{
Console. WriteLine ( "Car is running..." ) ;
}
}
class Truck : IVehicle
{
public void Run ( )
{
Console. WriteLine ( "Truck is running..." ) ;
}
}
interface IWeapon
{
void Fire ( ) ;
}
interface ITank : IVehicle , IWeapon
{
}
class LightTank : ITank
{
public void Fire ( )
{
Console. WriteLine ( "Boom!" ) ;
}
public void Run ( )
{
Console. WriteLine ( "LightTank Run..." ) ;
}
}
class MediumTank : ITank
{
public void Fire ( )
{
Console. WriteLine ( "Boom!" ) ;
}
public void Run ( )
{
Console. WriteLine ( "MediumTank!!! Run..." ) ;
}
}
class HeavyTank : ITank
{
public void Fire ( )
{
Console. WriteLine ( "Boom!" ) ;
}
public void Run ( )
{
Console. WriteLine ( "HeavyTank!!! Run..." ) ;
}
}
}
using Microsoft. Extensions. DependencyInjection;
using System;
namespace ConsoleApp2
{
class Program
{
static void Main ( string [ ] args)
{
var sc = new ServiceCollection ( ) ;
sc. AddScoped ( typeof ( ITank) , typeof ( MediumTank) ) ;
sc. AddScoped ( typeof ( IVehicle) , typeof ( Car) ) ;
sc. AddScoped < Driver > ( ) ;
var sp = sc. BuildServiceProvider ( ) ;
var driver = sp. GetService < Driver > ( ) ;
driver. Drive ( ) ;
}
}
class Driver
{
private IVehicle _vehicle;
public Driver ( IVehicle vehicle)
{
_vehicle = vehicle;
}
public void Drive ( )
{
_vehicle. Run ( ) ;
}
}
interface IVehicle
{
void Run ( ) ;
}
class Car : IVehicle
{
public void Run ( )
{
Console. WriteLine ( "Car is running..." ) ;
}
}
class Truck : IVehicle
{
public void Run ( )
{
Console. WriteLine ( "Truck is running..." ) ;
}
}
interface IWeapon
{
void Fire ( ) ;
}
interface ITank : IVehicle , IWeapon
{
}
class LightTank : ITank
{
public void Fire ( )
{
Console. WriteLine ( "Boom!" ) ;
}
public void Run ( )
{
Console. WriteLine ( "LightTank Run..." ) ;
}
}
class MediumTank : ITank
{
public void Fire ( )
{
Console. WriteLine ( "Boom!" ) ;
}
public void Run ( )
{
Console. WriteLine ( "MediumTank!!! Run..." ) ;
}
}
class HeavyTank : ITank
{
public void Fire ( )
{
Console. WriteLine ( "Boom!" ) ;
}
public void Run ( )
{
Console. WriteLine ( "HeavyTank!!! Run..." ) ;
}
}
}
using Microsoft. Extensions. DependencyInjection;
using System;
namespace ConsoleApp2
{
class Program
{
static void Main ( string [ ] args)
{
var sc = new ServiceCollection ( ) ;
sc. AddScoped ( typeof ( IVehicle) , typeof ( HeavyTank) ) ;
sc. AddScoped < Driver > ( ) ;
var sp = sc. BuildServiceProvider ( ) ;
var driver = sp. GetService < Driver > ( ) ;
driver. Drive ( ) ;
Driver driver1 = new Driver ( new HeavyTank ( ) ) ;
driver1. Drive ( ) ;
}
}
class Driver
{
private IVehicle _vehicle;
public Driver ( IVehicle vehicle)
{
_vehicle = vehicle;
}
public void Drive ( )
{
_vehicle. Run ( ) ;
}
}
interface IVehicle
{
void Run ( ) ;
}
class Car : IVehicle
{
public void Run ( )
{
Console. WriteLine ( "Car is running..." ) ;
}
}
class Truck : IVehicle
{
public void Run ( )
{
Console. WriteLine ( "Truck is running..." ) ;
}
}
interface IWeapon
{
void Fire ( ) ;
}
interface ITank : IVehicle , IWeapon
{
}
class LightTank : ITank
{
public void Fire ( )
{
Console. WriteLine ( "Boom!" ) ;
}
public void Run ( )
{
Console. WriteLine ( "LightTank Run..." ) ;
}
}
class MediumTank : ITank
{
public void Fire ( )
{
Console. WriteLine ( "Boom!" ) ;
}
public void Run ( )
{
Console. WriteLine ( "MediumTank!!! Run..." ) ;
}
}
class HeavyTank : ITank
{
public void Fire ( )
{
Console. WriteLine ( "Boom!" ) ;
}
public void Run ( )
{
Console. WriteLine ( "HeavyTank!!! Run..." ) ;
}
}
}