Skip to content

Support for IoC in instantiating Domain Model #1489

Closed as not planned
Closed as not planned

Description

@ravensorb

I am curious if there are any plans for supporting entity models that are based on design by contract and IoC.

Example Contract Based Model

public interface IAddress
{
    Guid Id { get; set; }
    string Line1 { get; set; }
    string Line2 { get; set; }
    string City { get; set; }
    string PostalCode { get; set; }
    string Country { get; set; }
}

public interface IOrderLine
{
    Guid Id { get; set; }
    IProduct Product { get; set; }
    decimal Price { get; set; }
}

public interface IOrder
{
    Guid Id { get; set; }
    IList<IOrderLine> LineItems { get; set; }
    DateTime CreatedOn { get; set; }
    IUser OrderedBy { get; set; }
}

public IProduct
{
    Guid Id { get; set; }
    string Name { get; set; }
    string Description { get; set; }
    decimal Price { get; set; }
}

public interface IUser 
{
    Guid Id { get; set; }
    string FullName { get; set; }
    IAddress PrimaryAddress { get; set; }
    IList<IAddress> Addresses { get; set; }
}

...

With this model, it should be possible to use it in an ORM as it contains everything that is needed. Ideally, it would be great if there was a way to tell EF to use a mapping possible via an IoC container resolution method.

Note: For the sake of simplicity, assume there is a set of concrete classes that implement the above contract model.

Example

var _container = new SimpleInjector.Container();

_container.Register<IUser, DbUser>();
_container,Register<IAddress, DbAdress>();
...

var ctx = new MyDbContext();
ctx.Resolver = (type) => _container.Resolver(type);

Activity

  1. rowanmiller commented on Jan 30, 2015

    @rowanmiller
    Contributor

    This is already tracked by #757 - we do want to support it but it won't be in the initial 7.0.0 RTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions