当调用用于存储对象的泛型方法时,偶尔需要以不同方式处理特定类型.我知道你不能基于约束重载,但任何其他替代方案似乎都存在自己的问题.
public bool Save<T>(T entity) where T : class
{ ... some storage logic ... }
我喜欢做的事情如下:
public bool Save<SpecificClass>(T entity)
{ ... special logic ... }
在过去,我们的团队已经创建了"一次性"方法来保存这些类,如下所示:
public bool SaveSpecificClass(SpecificClass sc)
{ ... special logic ... }
但是,如果您不知道该函数存在,并且您尝试使用泛型(保存),那么您可能遇到一系列问题,即"一次性"应该修复.如果一个新的开发人员出现,看到通用的问题,并决定他将用他自己的一次性功能来解决它,这可能会变得更糟.
所以...
解决这个看似常见的问题有哪些选择?
我已经看过了,并且使用了UnitOfWork,现在它似乎是实际解决问题的唯一选择 - 但似乎是用大锤攻击苍蝇.
我读过其他答案,但没有成功地使用 Angular 13 实现联合模块。我总是收到“共享模块不可用于急切消费”的消息。
长话短说:
- 仔细检查自定义 Webpack 配置中的公共路径 - 它可能缺少
/WebPack 可能错误地报告为“无法急切使用”的尾随。- 检查路由 - 您的 MFE/远程模块将在主机模块路由之后接收子路由(因此,如果您的主机在点击路由“登录”时路由到 MFE,则您的 MFE 将不会获得“登录”路径,它将获取一个空路径(请参阅下面的更新 2)。
- 可能需要(也可能不需要)引导(下面的更新 1)。
主机应用程序 webpack.config.ts:
export const webpackConfig: Configuration = {
  output: {
    publicPath: 'http://localhost:4200',
    uniqueName: 'host',
  },
  plugins: {
    new container.ModuleFederationPlugin({
      name: "host",
      remotes: {
        "remote-login": "login@http://localhost:4201/remoteEntry.js"
      }
      shared: [
        "@angular/core",
        "@angular/common",
        "@angular/router",
        "@angular/common/http",
      ]
    })
  ]
}
export default webpackConfig;
远程应用程序:
export const webpackConfig: Configuration = {
  output: {
    publicPath: 'http://localhost:4201',
  },
  optimization: { …我正在尝试创建一个可重用的 React 组件库供我们内部使用。
Webpack 正在捆绑输出 - 这应该是单个文件。但它实际上发布了我期望的 bundle.js和一个名为 [some_hash].worker.js 的文件。
我不确定如何强制 webpack 将“worker”文件包含在我要求的单个包中。
webpack.config:
const path = require('path');
const webpack = require('webpack');
const DIST_PATH = path.resolve(__dirname, "../dist");
const SRC_PATH = path.resolve(__dirname, "../src");
const APP_PATH = path.resolve(__dirname, "../src/index.js");
const BASE_PATH = path.resolve(__dirname);
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = ({ appPath = APP_PATH, distPath = DIST_PATH }) => ({
  context: BASE_PATH,
  devServer: {
    contentBase: distPath,
    compress: true,
    port: 9000,
    historyApiFallback: true
  },
  resolve: {
    modules: ['node_modules', …我们有一个 mono-repo,我正在将其迁移到 npm 7 的工作区。
当前文件夹组织:
\React
  - package.json (defines workspaces for \apps and \packages)
  \apps
    \someApp
      - React 17.0.1 (Dependency)
    \otherApp
  \packages
    \component-library
      - React 16.14.0 || 17.0.0 (Peer)
      - Storybook (6.1)
      - Storybook MUI Add On
    \framework
      - React 16.14.0 || 17.0.0 (Peer)
npm ci在 React 文件夹中运行会在 \React\node_modules 中安装 React 16.14,在 \React\apps\someApp\node_modules 中安装 17.0.0。当尝试运行该应用程序时,由于安装了多个版本,我们收到了预期的挂钩错误。但我找不到任何明确需要 React 16.14 的东西?
我只在iOS上收到错误:
TypeError: undefined is not an object (evaluating 'this._callListeners.bind')
This error is located at:
  in DrawerLayout (at DrawerView.js:161)
  ...
项目依赖项:
"dependencies": {
    "@babel/runtime": "7.2.0",
    "@babel/plugin-proposal-async-generator-functions": "7.2.0",
    "@babel/plugin-proposal-class-properties": "7.2.1",
    "@babel/plugin-proposal-object-rest-spread": "7.2.0",
    "babel-preset-expo": "5.0.0",
    "expo": "31.0.2",
    "expo-cli": "2.5.0",
    "native-base": "2.8.1",
    "react": "16.6.3",
    "react-native": "0.57.8",
    "react-redux": "6.0.0",
    "react-navigation": "3.0.8",
    "react-native-vector-icons": "6.1.0",
    "redux": "4.0.1"
  }
这开始于我开始使用反应导航; 但在Android上运行正常.
这是我们使用react-navigation的代码,这是导入包括Home和Settings屏幕的主要应用程序:
//imports...
const routes = {
  Home: Home,
  Settings: Settings
};
const AppNavigator = createDrawerNavigator(routes);
const AppContainer = createAppContainer(AppNavigator);
export default class App extends React.Component {
  state …如何设置链接服务器MVC3 Web.Config?  
我们有一个链接服务器,它有一个SP_PROC我们需要运行的存储过程.但是,主SQL服务器TESTSERVER1和链接服务器都是在测试环境中设置的TESTSERVER2,因此名称/ ip将在应用程序上线后更改.因此,我不想SP在代码中指定任何名称以外的内容.  
我已经尝试在连接字符串的初始目录字段中指定链接服务器,但是这会抛出错误 - 所以我假设我正在咆哮错误的树.
连接字符串示例:
<add name="connectionName" connectionString="data source=TESTSERVER1;Initial Catalog=TESTSERVER2;user id.../>