我只是想使用 AutoFac 来解决依赖关系,但它会引发异常,例如
请求的服务“ProductService”尚未注册。为了避免这个异常,要么注册一个组件来提供服务,要么使用 IsRegistered()...
class Program
{
static void Main(string[] args)
{
var builder = new ContainerBuilder();
builder.RegisterType<ProductService>().As<IProductService>();
using (var container = builder.Build())
{
container.Resolve<ProductService>().DoSomething();
}
}
}
public class ProductService : IProductService
{
public void DoSomething()
{
Console.WriteLine("I do lots of things!!!");
}
}
public interface IProductService
{
void DoSomething();
}
我做错了什么?