New to Autofac, followed a tutorial on Youtube(with great ratings) but its throwing an exception, no idea why.
Exceptions:
DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = IDomainRepository (ReflectionActivator), Services = [Solution.Entities.IDomainRepository], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope
And
NoConstructorsFoundException: No accessible constructors were found for the type 'Solution.Entities.IDomainRepository'.
IDomainRepository
public interface IDomainRepository
{
List<Domain> GetAll();
string Insert(Domain obj);
bool Update(Domain obj);
bool Delete(string URL);
}
DomainRepository
public class DomainRepository : IDomainRepository
{
public List<Domain> GetAll()
{
using (IDbConnection db = new SqlConnection(Helper.ConnectionString))
{
if (db.State == ConnectionState.Closed)
{
db.Open();
}
return db.Query<Domain>("SELECT * FROM Domains", commandType: CommandType.Text).ToList();
}
}
public string Insert(Domain obj)
{
using (IDbConnection db = new SqlConnection(Helper.ConnectionString))
{
if (db.State == ConnectionState.Closed)
{
db.Open();
}
db.Query<Domain>("INSERT INTO Domains (Domain) VALUES ("+obj.URL+")", commandType: CommandType.Text);
return obj.URL;
}
}
public bool Update(Domain obj)
{
using (IDbConnection db = new SqlConnection(Helper.ConnectionString))
{
if (db.State == ConnectionState.Closed)
{
db.Open();
}
int result = db.Execute("UPDATE Domains SET Domain="+obj.URL+" WHERE Domain="+obj.URL+")", commandType: CommandType.Text);
return result != 0;
}
}
public bool Delete(string URL)
{
using (IDbConnection db = new SqlConnection(Helper.ConnectionString))
{
if (db.State == ConnectionState.Closed)
{
db.Open();
}
int result = db.Execute("delete from Domains where Domain = @Url", new { Url = URL }, commandType: CommandType.Text);
return result != 0;
}
}
}
DomainHandler
static Autofac.IContainer _container;
static DomainHandler()
{
ContainerBuilder builder = new ContainerBuilder();
builder.RegisterType<IDomainRepository>().As<IDomainRepository>();
_container = builder.Build();
}
public static bool Delete(string Url)
{
return _container.Resolve<IDomainRepository>().Delete(Url);
}
public static List<Domain> GetAll()
{
return _container.Resolve<IDomainRepository>().GetAll();
}
public static Domain Save(Domain obj, EntityState state)
{
if (state == EntityState.Added)
obj.URL = _container.Resolve<IDomainRepository>().Insert(obj);
else
_container.Resolve<IDomainRepository>().Update(obj);
return obj;
}
Anyone know what might be causing this error? Read about forgetting to set public access on the interface but thats not the issue here.. :/