Closed ghost closed 10 years ago
This is more of a question for SimpleIoc than it is for Highway.
According to : http://stackoverflow.com/questions/13795596/best-tutorial-to-learn-mvvmlight-simpleioc-use
You would register a class with an interface as follows, it's their example 4 in the link above:
SimpleIoc.Default.Register<IDataContext>(context);
That SHOULD get it done, but again this really isn't a primary Highway concern.
I understand, for some reason this didn't solve it. I am making a comment on that post and will post the solution here when I find it.
One thing I am not clear on is the message is saying to provide an implementation of the IDbContextFactory and I am not registering this interface anywhere. Should I be?
It's weird because making a call to the database right before I register the IDataContext with the Ioc seems to resolve the issue. So that call must be registering something with the IDbContextFactory.
I am building a WPF application using the MVVM Light framework. When I try and register the IDataContext interface I am running into this error: The target context 'Highway.Data.DataContext' is not constructible. Add a default constructor or provide an implementation of IDbContextFactory.
I am trying to initialize the DataContext like so:
var context = new DataContext(connectionString, new ElverMappings()); SimpleIoc.Default.Register(() => { return context; });
However if a make a call to the database like the following, I don't get the error.
var repository = new Repository(context); repository.Context.AsQueryable().Any();
Right after I initialize the IDataContext, I also initialize the IMappingConfiguration, ILog, and IContextConfiguration.
Am I missing something?