我正在使用谷歌AutoFactory的注释处理器.我注释SomeClass与@AutoFactory和引用的new SomeClassFactory().create()是同一个模块在其他地方.
我在Maven中添加了必要的依赖:
<dependency>
<groupId>com.google.auto.factory</groupId>
<artifactId>auto-factory</artifactId>
<version>1.0-beta2</version>
<optional>true</optional>
</dependency>
Run Code Online (Sandbox Code Playgroud)
运行时,$ mvn clean compile我看到它target/generated-sources/annotions/somepackage/SomeClassFactory已创建,模块编译没有错误.
Reimport all maven modulesPreferences- > Annotation Processors- >Enable annotation processingRebuild Projectv14.1.4如果我的理解是正确的,那么在我的IDEA()版本中这应该足够了.
我还执行了以下步骤:
generated-sources文件夹已添加为源Project StructureGenerated sources folders已设置为Detect automaticallytarget首先删除文件夹以确保它是由IntelliJ生成的)Exclude output paths按照@tilpner的建议在项目结构中禁用.idea文件夹和.iml文件Phase to be used for …在我的一个Web应用程序中,我有一个使用Autofac的Web服务,其svc文件如下:
<%@ ServiceHost Language="C#" Debug="true"
Service="MyApp.WebServices.Contracts.Interfaces.IMyWebService, MyApp.WebServices.Contracts"
Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>
Run Code Online (Sandbox Code Playgroud)
我为我的Web服务应用程序注册依赖项,如下所示:
public class IocConfig
{
public static void RegisterDependencies()
{
var builder = new ContainerBuilder();
//web services
builder.RegisterType<MyWebService>().As<IMyWebService>().InstancePerLifetimeScope();
var container = builder.Build();
AutofacHostFactory.Container = container;
}
}
Run Code Online (Sandbox Code Playgroud)
从另一个Web应用程序,我也想使用Autofac连接到那些服务,所以我注册了类似的依赖项:
public class IocConfig
{
//Ioc dependencies for frontend application
public static void RegisterDependencies()
{
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.RegisterModule<AutofacWebTypesModule>();
builder
.Register(c => new ChannelFactory<ISomeWebService>(
new BasicHttpBinding(),
new EndpointAddress("http://localhost/MyApp.WebServices/MyWebService.svc")))
.InstancePerLifetimeScope();
//register service proxies
builder.Register(c => c.Resolve<ChannelFactory<IMyWebService>>().CreateChannel())
.As<IMyWebService>()
.UseWcfSafeRelease();
var container = …Run Code Online (Sandbox Code Playgroud)