This definitely appears to be a different issue than the Multithreading issue.
Using Unity with Dependency Injection(DI) for all my services and using an entity framework context which appears to be initialized and working correctly.
Currently using .net 4.5 with mvc and Unity.WebApi and entity framework 6.0.0.0.
I want to know if its possible to persist a service in this model or use outside of DI and be able to close and re-initialize entity framework in the persisted service if possible.
Currently getting this error when I try to persist a service through a stack class so its performance will be very fast b/c I'm using more frequently.
The Error message I am getting is: Error Message: The underlying provider failed on Open. - The connection was not closed. The connection's current state is connecting.( at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
Purpose is to retrieve only a single entity and make it load very fast compared to the dependency injected version and expose the results through a service. The entity is tied to a sql table for logging purposes.
Here is code snippet of why I'm trying to do to persist service:
using System;
using System.Linq;
using Davinci.Models;
namespace Services.Services
{
public interface ILogService
{
void SaveLog(UserLog log);
UserLog RetreiveLog(DateTime dateTime);
}
public class LogService : ILogService
{
private DavinciEntities _DavinciEntities;
public LogService(DavinciEntities context)
{
_DavinciEntities = context;
}
private void SaveLog(UserLog log)
{
_DavinciEntities.UserLogs.Add(log);
_DavinciEntities.SaveChanges();
}
public UserLog RetreiveLog(DateTime dateTime)
{
return _DavinciEntities.UserLogs.Where(m => m.LogTime.ToShortDateString() == dateTime.ToShortDateString()).FirstOrDefault();
}
}
public static class PersistService
{
public static UserLogService userLogService {get; set;}
public static void PersistUserLog(UserLogService service)
{
IUserLogService UserLogService;
if (UserAccessLog == null)
{
UserLogService = (UserLogService)context.Configuration.DependencyResolver.GetService(typeof(UserLogService));
}
}
}
}