Creates the main Program.cs file for the .NET application.
beforeCreateProgramFile(
{ resourceInfo }: dotnetTypes.DsgContext,
eventParams: dotnet.CreateProgramFileParams
) {
const serviceNamespace = pascalCase(resourceInfo?.name ?? "");
const serviceDbContext = `${pascalCase(resourceInfo?.name ?? "")}DbContext`;
eventParams.builderServicesBlocks.push(
new CodeBlock({
code: `builder.Services.AddDbContext<${serviceDbContext}>(opt => opt.UseNpgsql(builder.Configuration.GetConnectionString("${CONNECTION_STRING}")));`,
references: [
new ClassReference({
name: "AddDbContext",
namespace: "Microsoft.EntityFrameworkCore",
}),
new ClassReference({
name: serviceDbContext,
namespace: `${serviceNamespace}.Infrastructure`,
}),
],
})
);
return eventParams;
}
CreateProgramFile
An array of code blocks to be added to the builder.Services
section in Program.cs
.
An array of code blocks to be added to the application configuration section in Program.cs
.
beforeCreateProgramFile(
{ resourceInfo }: dotnetTypes.DsgContext,
eventParams: dotnet.CreateProgramFileParams
) {
const serviceNamespace = pascalCase(resourceInfo?.name ?? "");
const serviceDbContext = `${pascalCase(resourceInfo?.name ?? "")}DbContext`;
eventParams.builderServicesBlocks.push(
new CodeBlock({
code: `builder.Services.AddDbContext<${serviceDbContext}>(opt => opt.UseNpgsql(builder.Configuration.GetConnectionString("${CONNECTION_STRING}")));`,
references: [
new ClassReference({
name: "AddDbContext",
namespace: "Microsoft.EntityFrameworkCore",
}),
new ClassReference({
name: serviceDbContext,
namespace: `${serviceNamespace}.Infrastructure`,
}),
],
})
);
return eventParams;
}
Was this page helpful?
beforeCreateProgramFile(
{ resourceInfo }: dotnetTypes.DsgContext,
eventParams: dotnet.CreateProgramFileParams
) {
const serviceNamespace = pascalCase(resourceInfo?.name ?? "");
const serviceDbContext = `${pascalCase(resourceInfo?.name ?? "")}DbContext`;
eventParams.builderServicesBlocks.push(
new CodeBlock({
code: `builder.Services.AddDbContext<${serviceDbContext}>(opt => opt.UseNpgsql(builder.Configuration.GetConnectionString("${CONNECTION_STRING}")));`,
references: [
new ClassReference({
name: "AddDbContext",
namespace: "Microsoft.EntityFrameworkCore",
}),
new ClassReference({
name: serviceDbContext,
namespace: `${serviceNamespace}.Infrastructure`,
}),
],
})
);
return eventParams;
}
Creates the main Program.cs file for the .NET application.
beforeCreateProgramFile(
{ resourceInfo }: dotnetTypes.DsgContext,
eventParams: dotnet.CreateProgramFileParams
) {
const serviceNamespace = pascalCase(resourceInfo?.name ?? "");
const serviceDbContext = `${pascalCase(resourceInfo?.name ?? "")}DbContext`;
eventParams.builderServicesBlocks.push(
new CodeBlock({
code: `builder.Services.AddDbContext<${serviceDbContext}>(opt => opt.UseNpgsql(builder.Configuration.GetConnectionString("${CONNECTION_STRING}")));`,
references: [
new ClassReference({
name: "AddDbContext",
namespace: "Microsoft.EntityFrameworkCore",
}),
new ClassReference({
name: serviceDbContext,
namespace: `${serviceNamespace}.Infrastructure`,
}),
],
})
);
return eventParams;
}
CreateProgramFile
An array of code blocks to be added to the builder.Services
section in Program.cs
.
An array of code blocks to be added to the application configuration section in Program.cs
.
beforeCreateProgramFile(
{ resourceInfo }: dotnetTypes.DsgContext,
eventParams: dotnet.CreateProgramFileParams
) {
const serviceNamespace = pascalCase(resourceInfo?.name ?? "");
const serviceDbContext = `${pascalCase(resourceInfo?.name ?? "")}DbContext`;
eventParams.builderServicesBlocks.push(
new CodeBlock({
code: `builder.Services.AddDbContext<${serviceDbContext}>(opt => opt.UseNpgsql(builder.Configuration.GetConnectionString("${CONNECTION_STRING}")));`,
references: [
new ClassReference({
name: "AddDbContext",
namespace: "Microsoft.EntityFrameworkCore",
}),
new ClassReference({
name: serviceDbContext,
namespace: `${serviceNamespace}.Infrastructure`,
}),
],
})
);
return eventParams;
}
Was this page helpful?
beforeCreateProgramFile(
{ resourceInfo }: dotnetTypes.DsgContext,
eventParams: dotnet.CreateProgramFileParams
) {
const serviceNamespace = pascalCase(resourceInfo?.name ?? "");
const serviceDbContext = `${pascalCase(resourceInfo?.name ?? "")}DbContext`;
eventParams.builderServicesBlocks.push(
new CodeBlock({
code: `builder.Services.AddDbContext<${serviceDbContext}>(opt => opt.UseNpgsql(builder.Configuration.GetConnectionString("${CONNECTION_STRING}")));`,
references: [
new ClassReference({
name: "AddDbContext",
namespace: "Microsoft.EntityFrameworkCore",
}),
new ClassReference({
name: serviceDbContext,
namespace: `${serviceNamespace}.Infrastructure`,
}),
],
})
);
return eventParams;
}