Skip to content

Instantly share code, notes, and snippets.

public interface IShape<T> where T : class {}
public class Rectangle : IShape<Rectangle>
{
public Rectangle() { }
}
services.AddTransient<IShape<Rectangle>, Rectangle>();
services.AddTransient<IShape<Circle>, Circle>();
private readonly IShape<Rectangle> _rectangle;
private readonly IShape<Circle> _circle;
public WindowManager(IShape<Rectangle> rectangle, IShape<Circle> circle)
{
this._rectangle = rectangle ?? throw new ArgumentNullException(nameof(rectangle));
this._circle = circle ?? throw new ArgumentNullException(nameof(circle));
}
public interface IShapeFactory<T> where T : IShape
{
IShape CreateShape();
}
public class WindowManager
{
private readonly IShapeFactory<Rectangle> _rectangleFactory;
private readonly IShapeFactory<Cirlce> _CircleFactory;
public WindowManager(IShapeFactory<Rectangle> rectangleFactory, IShapeFactory<Cirlce> CirlceFactory)
{
this._rectangleFactory = rectangleFactory ?? throw new ArgumentNullException(nameof(rectangleFactory));
this._CircleFactory = CirlceFactory ?? throw new ArgumentNullException(nameof(CirlceFactory));
}
public interface IShapeParameters { }
services.AddTransient<IShape, Rectangle>();
services.AddTransient<IShape, Circle>();
private readonly IShape _rectangle;
private readonly IShape _circle;
public WindowManager(IShape rectangle, IShape circle)
{
this._rectangle = rectangle ?? throw new ArgumentNullException(nameof(rectangle));
this._circle = cirlce ?? throw new ArgumentNullException(nameof(circle));
}
public class RectangleParameters : IShapeParameters
{
public double width { get; set; }
public double height { get; set; }
}