Skip to content

Instantly share code, notes, and snippets.

@lukebakken
Last active July 30, 2016 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukebakken/1a77dd6ebc515753ef7170e841a22f62 to your computer and use it in GitHub Desktop.
Save lukebakken/1a77dd6ebc515753ef7170e841a22f62 to your computer and use it in GitHub Desktop.
di-configure-object
public interface IYoMamaService
{
    bool IsSoFat { get; }
}

public interface IYoMamaServiceConfig
{
    int SoFatSize { get; }
}

public interface IMamaDataSource
{
    int Weigh();
}

public class FrazzleService : IYoMamaService
{
    private readonly IYoMamaServiceConfig config;
    // OR
    private readonly int soFatSize;
    
    private readonly IMamaDataSource ds;

    public FrazzleService(IYoMamaServiceConfig config, IMamaDataSource ds)
    {
        if (config == null)
        {
            throw new ArgumentNullException(config, "WAT");
        }
        
        if (ds == null)
        {
            throw new ArgumentNullException("ds", "WAT");
        }

        this.config = config;
        // OR
        this.soFatSize = config.SoFatSize;
        
        this.ds = ds;
    }

    public bool IsSoFat
    {
        get
        {
            return ds.Weigh() > config.SoFatSize;
            // OR
            return ds.Weigh() > soFatSize;
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment